I got fed up with the slowness of mine on my MacBook Pro, so I rewrote them from scratch in January for Tiger or later only. I never got round to uploading them. Here they are. By the way, the rather lame name “Open Dictionaries” isn’t mine. It was given to an early version of the Running Apps script by a MacScripter administrator who transfered it to ScriptBuilders from some earlier feature of this site. Script of the Week, I think.
Running Apps:
(* Dictionaries - Running Apps (Open Dictionaries 2.2.2), by Nigel Garvey, January 2012 *)
main()
on main()
tell application "Finder" to set sysv to (system attribute "sysv")
if (sysv < 4160) then abort("This version of the script only supports Mac OS X 10.4.0 or later.")
set editorName to getEditorName()
openDictionaries(editorName)
end main
on getEditorName()
-- Check that either Script Editor, Smile, or Script Debugger is running.
tell application "System Events" to set {editorNames, editorFrontmosts} to {name, frontmost} of (every application process whose creator type is "ToyS" or creator type is "VIZF" or creator type is "asDB")
set editorCount to (count editorNames)
if (editorCount is 0) then
my abort("Please open (Apple)Script Editor, Smile, or Script Debugger before using this script.")
else if (editorCount is 1) then
-- One of the editors is running.
set editorName to beginning of editorNames
else if (editorFrontmosts contains true) then
-- More than one of the editors is running. If one is the frontmost app, use that.
repeat with i from 1 to editorCount
if (item i of editorFrontmosts) then
set editorName to item i of editorNames
exit repeat
end if
end repeat
else
-- Otherwise consult the user for which editor to use.
tell application (path to frontmost application as Unicode text) to set theChoice to (choose from list editorNames with prompt "In which editor do you want to view the dictionaries?" with title "Dictionaries - Running Apps")
if (theChoice is false) then error number -128
set editorName to beginning of theChoice
end if
return editorName
end getEditorName
on abort(msg)
tell application (path to frontmost application as Unicode text) to display dialog msg buttons {"Cancel"} default button 1 with icon stop cancel button 1 with title "Dictionaries - Running Apps"
end abort
on openDictionaries(editorName)
set specialNames to {"Finder"}
tell application "System Events" to tell (application processes whose has scripting terminology is true and name is not "Image Capture Scripting") to set {procNames, procFiles} to {its name, its file}
specialSort(procNames, procFiles, specialNames)
tell application (path to frontmost application as Unicode text) to set theChoice to (choose from list procNames default items specialNames with prompt "Which dictionaries do you want to open?" with title "Dictionaries - Running Apps" with multiple selections allowed)
if (theChoice is false) then error number -128
set theFiles to {}
repeat with i from 1 to (count procNames)
if (item i of procNames is in theChoice) then set end of theFiles to item i of procFiles
end repeat
tell application editorName to open theFiles
end openDictionaries
on specialSort(procNames, procFiles, specialNames)
-- This script customises the sort to group any "special" application names before the others. It does this by judging non-special names to have higher comparison values.
script specialsFirst
property specials : specialNames
on isGreater(a, b)
set |b's special| to (b is in specials)
if ((|b's special|) = (a is in specials)) then
(a > b)
else
(|b's special|)
end if
end isGreater
end script
-- This script duplicates in procFiles moves performed in procNames by the custom insertion sort.
script parallel
property lst : procFiles
on shift(a, b)
tell item b of my lst
repeat with i from b - 1 to a by -1
set item (i + 1) of my lst to item i of my lst
end repeat
set item a of my lst to it
end tell
end shift
end script
CustomInsertionSort(procNames, 1, -1, {comparer:specialsFirst, slave:parallel})
end specialSort
-- Custom insertion sort from A Dose of Sorts by Nigel Garvey.
on CustomInsertionSort(theList, l, r, customiser)
script o
property comparer : me
property slave : me
property lst : theList
on isrt(l, r)
set u to item l of o's lst
repeat with j from (l + 1) to r
set v to item j of o's lst
if (comparer's isGreater(u, v)) then
set here to l
set item j of o's lst to u
repeat with i from (j - 2) to l by -1
tell item i of o's lst
if (comparer's isGreater(it, v)) then
set item (i + 1) of o's lst to it
else
set here to i + 1
exit repeat
end if
end tell
end repeat
set item here of o's lst to v
slave's shift(here, j)
else
set u to v
end if
end repeat
end isrt
-- Default comparison and slave handlers to customise for an ordinary sort.
on isGreater(a, b)
(a > b)
end isGreater
on shift(a, b)
end shift
end script
-- Process the input parmeters.
set listLen to (count theList)
if (listLen > 1) then
-- Negative and/or transposed range indices.
if (l < 0) then set l to listLen + l + 1
if (r < 0) then set r to listLen + r + 1
if (l > r) then set {l, r} to {r, l}
-- Supplied or default customisation scripts.
if (customiser's class is record) then set {comparer:o's comparer, slave:o's slave} to (customiser & {comparer:o, slave:o})
-- Do the sort.
o's isrt(l, r)
end if
return -- nothing.
end CustomInsertionSort
OSAXen:
(* Dictionaries - OSAXen (Open Dictionaries 2.2.2), by Nigel Garvey, January 2012 *)
main()
on main()
tell application "Finder" to set sysv to (system attribute "sysv")
if (sysv < 4160) then abort("This version of the script only supports Mac OS X 10.4.0 or later.")
set editorName to getEditorName()
openDictionaries(editorName)
end main
on getEditorName()
-- Check that either Script Editor, Smile, or Script Debugger is running.
tell application "System Events" to set {editorNames, editorFrontmosts} to {name, frontmost} of (every application process whose creator type is "ToyS" or creator type is "VIZF" or creator type is "asDB")
set editorCount to (count editorNames)
if (editorCount is 0) then
my abort("Please open (Apple)Script Editor, Smile, or Script Debugger before using this script.")
else if (editorCount is 1) then
-- One of the editors is running.
set editorName to beginning of editorNames
else if (editorFrontmosts contains true) then
-- More than one of the editors is running. If one is the frontmost app, use that.
repeat with i from 1 to editorCount
if (item i of editorFrontmosts) then
set editorName to item i of editorNames
exit repeat
end if
end repeat
else
-- Otherwise consult the user for which editor to use.
tell application (path to frontmost application as Unicode text) to set theChoice to (choose from list editorNames with prompt "In which editor do you want to view the dictionaries?" with title "Dictionaries - Running Apps")
if (theChoice is false) then error number -128
set editorName to beginning of theChoice
end if
return editorName
end getEditorName
on abort(msg)
tell application (path to frontmost application as Unicode text) to display dialog msg buttons {"Cancel"} default button 1 with icon stop cancel button 1 with title "Dictionaries - Running Apps"
end abort
on openDictionaries(editorName)
tell application "System Events"
set {systemNames, systemPaths} to {name, path} of (files of scripting additions folder of system domain where it is visible and name is not "Image Capture Scripting.app")
set {localNames, localPaths} to {name, path} of (files of scripting additions folder of local domain where it is visible)
set {userNames, userPaths} to {name, path} of (files of scripting additions folder of user domain where it is visible)
end tell
specialSort(systemNames, systemPaths)
specialSort(localNames, localPaths)
specialSort(userNames, userPaths)
set allNames to systemNames & localNames & userNames
set allPaths to systemPaths & localPaths & userPaths
set chooseList to insertDivider(systemNames)
if (localNames is not {}) then set chooseList to chooseList & separator() & insertDivider(localNames)
if (userNames is not {}) then set chooseList to chooseList & separator() & insertDivider(userNames)
tell application (path to frontmost application as Unicode text) to set theChoice to (choose from list chooseList with prompt "Which OSAXen and/or scripting application dictionaries do you want to open?" default items {"StandardAdditions.osax"} with title "Dictionaries - OSAXen" with multiple selections allowed)
if (theChoice is false) then error number -128
repeat with i from 1 to (count allNames)
if (item i of allNames is in theChoice) then tell application editorName to open file (item i of allPaths)
end repeat
end openDictionaries
on insertDivider(nameList)
if (end of nameList ends with ".app") then
repeat with i from 1 to (count nameList)
if (item i of nameList ends with ".app") then exit repeat
end repeat
set nameList to items 1 thru (i - 1) of nameList & divider() & items i thru -1 of nameList
end if
return nameList
end insertDivider
on divider()
return "···············"
end divider
on separator()
return "----------"
end separator
on specialSort(fileNames, filePaths)
script specialsFirst
on isGreater(a, b)
if (b ends with ".osax") then
((a ends with ".app") or (b is "StandardAdditions.osax") or ((a > b) and (a is not "StandardAdditions.osax")))
else
((a ends with ".app") and (a > b))
end if
end isGreater
end script
-- This script duplicates in filePaths moves performed in fileNames by the custom insertion sort.
script parallel
property lst : filePaths
on shift(a, b)
tell item b of my lst
repeat with i from b - 1 to a by -1
set item (i + 1) of my lst to item i of my lst
end repeat
set item a of my lst to it
end tell
end shift
end script
CustomInsertionSort(fileNames, 1, -1, {comparer:specialsFirst, slave:parallel})
end specialSort
-- Custom insertion sort from A Dose of Sorts by Nigel Garvey.
on CustomInsertionSort(theList, l, r, customiser)
script o
property comparer : me
property slave : me
property lst : theList
on isrt(l, r)
set u to item l of o's lst
repeat with j from (l + 1) to r
set v to item j of o's lst
if (comparer's isGreater(u, v)) then
set here to l
set item j of o's lst to u
repeat with i from (j - 2) to l by -1
tell item i of o's lst
if (comparer's isGreater(it, v)) then
set item (i + 1) of o's lst to it
else
set here to i + 1
exit repeat
end if
end tell
end repeat
set item here of o's lst to v
slave's shift(here, j)
else
set u to v
end if
end repeat
end isrt
-- Default comparison and slave handlers to customise for an ordinary sort.
on isGreater(a, b)
(a > b)
end isGreater
on shift(a, b)
end shift
end script
-- Process the input parmeters.
set listLen to (count theList)
if (listLen > 1) then
-- Negative and/or transposed range indices.
if (l < 0) then set l to listLen + l + 1
if (r < 0) then set r to listLen + r + 1
if (l > r) then set {l, r} to {r, l}
-- Supplied or default customisation scripts.
if (customiser's class is record) then set {comparer:o's comparer, slave:o's slave} to (customiser & {comparer:o, slave:o})
-- Do the sort.
o's isrt(l, r)
end if
return -- nothing.
end CustomInsertionSort
Core Services:
(* Dictionaries - Core Services (Open Dictionaries 2.2.2), by Nigel Garvey, January 2012 *)
main()
on main()
tell application "Finder" to set sysv to (system attribute "sysv")
if (sysv < 4160) then abort("This version of the script only supports Mac OS X 10.4.0 or later.")
set editorName to getEditorName()
openDictionaries(editorName)
end main
on getEditorName()
-- Check that either Script Editor, Smile, or Script Debugger is running.
tell application "System Events" to set {editorNames, editorFrontmosts} to {name, frontmost} of (every application process whose creator type is "ToyS" or creator type is "VIZF" or creator type is "asDB")
set editorCount to (count editorNames)
if (editorCount is 0) then
my abort("Please open (Apple)Script Editor, Smile, or Script Debugger before using this script.")
else if (editorCount is 1) then
-- One of the editors is running.
set editorName to beginning of editorNames
else if (editorFrontmosts contains true) then
-- More than one of the editors is running. If one is the frontmost app, use that.
repeat with i from 1 to editorCount
if (item i of editorFrontmosts) then
set editorName to item i of editorNames
exit repeat
end if
end repeat
else
-- Otherwise consult the user for which editor to use.
tell application (path to frontmost application as Unicode text) to set theChoice to (choose from list editorNames with prompt "In which editor do you want to view the dictionaries?" with title "Dictionaries - CoreServices")
if (theChoice is false) then error number -128
set editorName to beginning of theChoice
end if
return editorName
end getEditorName
on abort(msg)
tell application (path to frontmost application as Unicode text) to display dialog msg buttons {"Cancel"} default button 1 with icon stop cancel button 1 with title "Dictionaries - CoreServices"
end abort
on openDictionaries(editorName)
set coreServicesFolder to ((path to library folder as Unicode text from system domain) & "CoreServices:") as alias
tell application "Finder"
set {appNames, appScriptabilities} to {name, has scripting terminology} of application files of coreServicesFolder
set appAliases to (application files of coreServicesFolder) as alias list
end tell
repeat with i from 1 to (count appScriptabilities)
if (item i of appScriptabilities) then
else
set item i of appNames to missing value
set item i of appAliases to missing value
end if
end repeat
set appNames to appNames's every Unicode text
set appAliases to appAliases's every alias
tell application (path to frontmost application as Unicode text) to set chosenNames to (choose from list appNames with prompt "Which CoreService dictionaries do you want to open?" with title "Dictionaries - CoreServices" with multiple selections allowed)
if (chosenNames is false) then error number -128
repeat with i from 1 to (count appNames)
if (item i of appNames is in chosenNames) then tell application editorName to open item i of appAliases
end repeat
end openDictionariess
Edit: Replaced the em dashes in the opening comments with ordinary dashes. The compiler doesn’t seem to like them in single-line (* . *) comments. Weird.