Re: Prevent asking to locate application
Re: Prevent asking to locate application
- Subject: Re: Prevent asking to locate application
- From: Joseph Weaks <email@hidden>
- Date: Sun, 28 Mar 2004 23:29:27 -0600
I want to
send a script to other users for them to use. They provide the name of
the app in a dialog and then the script does it's stuff in that app
when the time comes to paste result in a word processor.
What if they misspell it? How will your script know what they meant?
That part is all taken care of. I guess I should have posted more
script so you can see what's being done. Here is a skeleton of the
architecture. I've removed the error handlers that check to make sure
the there is an app running whose name is theApp.
--BEGIN SCRIPT
if theApp is "Microsoft Word" then
pasteInWord()
else if theApp is "Appleworks" then
pasteInAppleworks()
else
pasteInGeneric(theApp)
end if
on pasteInWord()
tell application "Microsoft Word" to activate
tell application "Finder" to activate
-- This little jump to Finder prevents a wierd "ghosted window" problem
in Word.
tell application "Microsoft Word"
do Visual Basic "Application.Activate
' Should insert a check to verify a doc is open or create new one
Selection.Collapse wdCollapseEnd
Selection.Paste"
end tell
end pasteInWord
on pasteInAppleworks()
tell application "AppleWorks 6"
activate
if not (exists document 1) then make new document at front with
properties {document kind:text document}
delay 1
paste
delay 1 --give it time to update
end if
end tell
end pasteInAppleworks
on pasteInGeneric(theApp)
--Paste clipboard into any app in 10.3
tell application theApp
tell application "System Events"
try
set theProcess to item 1 of (every process whose frontmost is true)
tell theProcess to keystroke "v" using command down
on error msg
display dialog msg with icon 0
end try
end tell
end tell
delay 1 --give it time to update
end pasteInGeneric
-- END SCRIPT
Also, with the current setup, I was thinking I could place each handler
into a string and then run that script as a string. It wouldn't compile
and so the app that folks didn't have would never get searched for.
Something like
set AppleworksScript to "tell application \"AppleWorks 6\"
activate
if not (exists document 1) then make new document at front with
properties {document kind:text document}
delay 1
paste
delay 1 --give it time to update
end if
end tell"
if theApp is "Appleworks" then
run script AppleworksScript
else if...
I'm starting to think that individual handlers is a stupid way to do
all this. Perhaps I should use something more like:
tell app theApp to activate
if theApp is "Appleworks" then
--Appleworks code
else if theApp is "Microsoft Word" then
--Word VBA code
...
end if
You agree?
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.