Re: UI script fails when run from Mail.app's script menu **Workaround**
Re: UI script fails when run from Mail.app's script menu **Workaround**
- Subject: Re: UI script fails when run from Mail.app's script menu **Workaround**
- From: Joseph Weaks <email@hidden>
- Date: Sat, 20 Mar 2004 18:51:07 -0600
On Mar 20, 2004, at 4:51 PM, Robert Poland wrote:
I had a similar problem with a GI script in the GraphisConvertor
scripts folder. My cure was to use a script (in GraphisConvertor) to
call the script (in the Universal Scripts scripts folder).
This is the workaround I got working, too, but first more on the
original problem. This line actually works in a script place in
mail.app's script folder:
tell application "System Events" to keystroke "c" using command down
delay 1
However, as soon as you start adding additional code such as
display dialog "anything"
or
run script alias myScript
then the script fails... the command c does not get copy the text
selected.
I'd like to understand why this is (it's not an issue of how long the
delay is), so that we could do a one script workaround.
My current workaround involves the trigger script that simply puts the
name of the front app on the clipboard and then calls an applet to do
the real work if copying the text selection from the original document
and processes it:
--###########
--Begin Script placed inside any application's script folder
tell application "System Events" to set theProcess to name of (first
process whose frontmost is true)
set the clipboard to theProcess
set scriptPath to (((path to scripts folder) as string) &
"copyFromCurrentApp")
tell application "Finder" to open file scriptPath
--End Script
--###########
--Begin Script APPLICATION named "copyFromCurrentApp" placed inside
Home/Library/Scripts folder
set theProcess to the clipboard as string
tell application theProcess
activate
tell application "System Events"
tell process theProcess
keystroke "c" using command down
delay 1 --give it time to update
end tell
end tell
end tell
display dialog "the clipboard: " & (the clipboard)
-- or run whatever methods you want now that you have the selected text
in hand
--End Script
--###########
Better solutions? The applet solution works because the script is no
longer dependent upon the original app's implementation of Applescript,
I guess. I tried various attempts at
set shellScript to "osascript -e 'tell application \"System Events\" to
keystroke \"c\" using command down'"
but to no avail.
All of this would be unnecessary if they would add the Applescript
command:
set theProcess to the name of the app whose frontmost was true just
before the app whose frontmost is true became the frontmost app
:)
Still puzzled, but slightlier happy,
Joe Weaks
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.