• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Prevent asking to locate application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Prevent asking to locate application
      • From: Walter Ian Kaye <email@hidden>
References: 
 >Prevent asking to locate application (From: Joseph Weaks <email@hidden>)
 >Re: Prevent asking to locate application (From: Hanaan Rosenthal <email@hidden>)
 >Re: Prevent asking to locate application (From: Joseph Weaks <email@hidden>)
 >Re: Prevent asking to locate application (From: Walter Ian Kaye <email@hidden>)

  • Prev by Date: Re: applescript-users digest, Vol 3 #2563 - 9 msgs
  • Next by Date: Re: AppleScript & HTML Again...
  • Previous by thread: Re: Prevent asking to locate application
  • Next by thread: Re: Prevent asking to locate application
  • Index(es):
    • Date
    • Thread