An AppleScript to quickly launch applications

Feb 23, '04 10:22:00AM

Contributed by: RickoKid

I find it a bit of a time waster to open up my Applications folder everytime I want to open an application I don't use that often (as in: I don't have it bound to a keyboard shortcut using Keyboard Maestro like I do my more common applications). In KDE on linux I can press Alt-F2 to bring up a box that I can type the name of an executable file and it will load - I wanted something similar on my Mac.

So I wrote this Applescript that will bring up a window so you can type in the name of the application you want to start. Then I improved that so that it saves the applications you run in a list so you get a list of the most recently run applications you used it to launch - plus an "Other ..." option for a new application. You can change the number of entries it saves by changing the number 10 on the first line of the script. I then use Keyboard Maestro to bind it to a key (I use F13).

BTW: I know LaunchBar or some other shareware probably does this along with a whole lot of other things .. but I don't have it and don't need all the other functionality!

Here's the script:


set rememberEntries to 10

set runList to {}
set runListString to "Safari,Address Book,Mail"
set lastRun to "Safari"
set savedTextItemDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}

try
  set lastRun to do shell script "defaults read com.rickosoft.actUp lastRun"
  set runListString to do shell script "defaults read com.rickosoft.actUp runList"
end try

set runList to (text items of runListString & ("Other ..." as list))

try
  set runApp to ¬
  (choose from list runList with prompt ¬
  "Choose Application to activate" default items (last item of runList) ¬
  OK button name ¬
  "Choose" with multiple selections allowed and empty selection allowed)
  repeat with anApp in runApp
    if anApp contains "Other ..." then
      set runNow to text returned of ¬
      (display dialog "Name of Application to activate?" default answer lastRun)
      set lastRun to runNow
      set runApp to runApp & runNow
    else
      set runNow to anApp
    end if
    tell application runNow to activate
  end repeat
  on error
  return "User cancelled"
end try

set outRunApp to {}
repeat with runAppItem in runApp
  if runAppItem as string is not "Other ..." then
    if outRunApp does not contain runAppItem then ¬
    set outRunApp to outRunApp & runAppItem
  end if
end repeat
set outRunList to outRunApp -- Promote/Add the run app to the top of the list
repeat with runListItem in runList
  if runListItem as string is not "Other ..." and (count of outRunList) ¬
  is less than rememberEntries then
    if outRunList does not contain runListItem then set outRunList ¬
    to outRunList & runListItem
  end if
end repeat
set runListString to "\"" & (outRunList as text) & "\""
if outRunApp is equal to {} then set outRunApp to lastRun as list

do shell script "defaults write com.rickosoft.actUp lastRun \"" & ¬
last item of outRunApp & "\""
do shell script "defaults write com.rickosoft.actUp runList " ¬
& runListString

set AppleScript's text item delimiters to savedTextItemDelimiters
return true
[robg adds: This works exactly as described...]

Comments (34)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040215160635872