(* AppScript Launcher 0.1 by Tumbleseed (http://www.torrfamily.org/tumbleseed/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *) set rememberEntries to 10 set runList to {} set runApp to {} set runListString to "Safari,Address Book,Mail" set savedTextItemDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {","} set otherText to "Other Application ..." set editText to "Edit entries ..." set newText to "[New entry]" try set runListString to do shell script "defaults read org.tumbleseed.appscript runList" end try set runList to (text items of runListString) try set appsChosen to false repeat until appsChosen if runApp is {} then set runApp to ¬ (choose from list ({editText, otherText} & text items of runList) with title "AppScript Launcher" with prompt ¬ "Choose Application to activate:" & return & return & ¬ "Tip: You can select multiple entries (apart from " & editText & ") and they will all be activated." default items otherText ¬ with multiple selections allowed without empty selection allowed) if runApp contains editText then set editApp to (choose from list ({newText} & runList) with title editText with prompt ¬ "Which entry would you like to edit?" OK button name ¬ "Edit" cancel button name ¬ "Back" with multiple selections allowed without empty selection allowed) if editApp is false then set runApp to {} else if (count of editApp) is 1 then set editAction to (display dialog "" default answer editApp buttons {"Back", "Delete", "Save"} default button "Save" giving up after 30 with title "Editing \"" & editApp & "\"") else if editApp contains newText then set editApp to (my deleteFromList(newText, editApp)) set editAction to (display dialog "Do you really want to delete the following entries:" & ¬ return & return & ¬ editApp as string buttons {"Back", "Delete"} default button "Delete" giving up after 30 with title "Editing multiple entries") end if if button returned of editAction is equal to "Delete" then -- delete entry repeat with eachApp in editApp set runList to my deleteFromList(eachApp, runList) end repeat my writeDefaults(runList) else if button returned of editAction is equal to "Save" then -- save edited text as entry set newEntry to (application (text returned of editAction) as text) set runList to my replaceInList(editApp, newEntry, runList) my writeDefaults(runList) else if button returned of editAction is equal to "Back" then end if end if else exit repeat set appsChosen to true end if end repeat repeat with anApp in runApp if anApp contains otherText then set runNow to ¬ (display dialog ¬ "Type the name of the application to activate." & return & return & ¬ "If application cannot be found the Browse window will appear." with title otherText ¬ default answer "" buttons {"Cancel", "Browse", "OK"} ¬ default button "OK") if button returned of runNow is "Browse" then set runNow to (choose application) as text else set runNow to (application (text returned of runNow) as text) end if set runApp to runApp & runNow else set runNow to anApp end if ignoring application responses if runNow is not "" then tell application runNow to activate end ignoring end repeat on error errMsg return errMsg end try set outRunApp to {} repeat with runAppItem in runApp if runAppItem as string is not otherText and runAppItem as string is not editText 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 otherText 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 my writeDefaults(outRunList) set AppleScript's text item delimiters to savedTextItemDelimiters return true on writeDefaults(runList) set runListString to "\"" & (runList as text) & "\"" do shell script ¬ "defaults write org.tumbleseed.appscript runList " & runListString end writeDefaults on deleteFromList(entry, fullList) if fullList does not contain entry then return fullList set newList to {} repeat with eachEntry in fullList if eachEntry does not contain entry then set newList to newList & {eachEntry as item} end if end repeat return newList end deleteFromList on replaceInList(search, replace, fullList) if fullList does not contain search then return {replace} & fullList set newList to {} repeat with eachEntry in fullList if eachEntry does not contain search then set newList to newList & {eachEntry as item} else set newList to newList & {replace} end if end repeat return newList end replaceInList