Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.6: Create new AppleScript document Service' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Create new AppleScript document Service
Authored by: Lri on Mar 26, '11 04:16:48AM
Another version:
-- 'Service receives selected: text' could still be more convenient
tell application "System Events"
	set old to the clipboard
	set proc to process 1 where frontmost is true
	try
		tell proc
			click menu bar 1's menu bar item "Edit"'s menu 1's menu item "Copy"
		end tell
	on error
		try
			delay 0.3 -- time to release modifier keys if triggered with a shortcut
			keystroke "c" using {command down}
		on error
			return
		end try
	end try
	delay 0.05
	set x to the clipboard as text
end tell

tell application "AppleScript Editor"
	-- for some reason, 'with properties {contents:x}' checks for errors
	-- sometimes the dialog appears behind the new window, sometimes nowhere
	set doc to make new document
	set text of doc to x
	set bounds of window 1 to {420, 22, 1500, 1100}
	activate
end tell

set the clipboard to old
The biggest difference is that it uses the oldskool way for getting the selection, so it doesn't have to be saved as an Automator service.

[ Reply to This | # ]