• 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
snippet for automatically choosing an application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

snippet for automatically choosing an application


  • Subject: snippet for automatically choosing an application
  • From: Victor Yee <email@hidden>
  • Date: Thu, 28 Jun 2001 08:33:13 -0400

Here's a little snippet for automatically choosing an application from a list of creator types.

It will first check running processes, then check and launch by application file id. It returns the first available requested application, determined by the order of items in the list of creator types.

Result: application process as <<class psn >>
(see John Delacour's method for "Using a Variable to Send Events"
<http://members.tripod.co.uk/scripting/applescript/doubletell.html>)

------
set x to {"QEdt", "TBB6", "Stl"} -- creator types for: QuoEdit, Tex-Edit Plus, Style

autoChooseApp(x)

on autoChooseApp(appList)
set thisApp to checkRunning(appList) as string
if thisApp is "" then set thisApp to checkAvailable(appList)
if thisApp is "" then
error "None of the requested applications are available." number -2700
else
return getAppPSN(thisApp)
end if
end autoChooseApp

on checkRunning(appList)
tell application "Finder"
return creator type of (first process whose creator type is in appList)
end tell
end checkRunning

on checkAvailable(appList)
tell application "Finder"
repeat with appType in appList
if exists application file id appType then
open application file id appType
return appType
end if
end repeat
end tell
return ""
end checkAvailable

on getAppPSN(appType)
tell application "Finder"
return (first process whose creator type is appType) as +class psn ;
end tell
end getAppPSN
------

Victor


  • Prev by Date: Re: PhotoScripter and Curves
  • Next by Date: Scripting ASIP Server actions
  • Previous by thread: Re: Date & Time Control Panel
  • Next by thread: Scripting ASIP Server actions
  • Index(es):
    • Date
    • Thread