Two things. In the last repeat loop of the script below I accidentally used this:
--repeat with thisScriptLibrary in userChoice
Which told SD to open the name of the file rather than it’s alias.
A goof like that should result in an apple event error, but instead I got a hard crash. Crashed SD when run from SE too. (The version below is fixed and does not crash, but the bad repeat command is noted out if you want to crash your version).
Second thing,
the showing dictionary parameter of SD’s open command doesn’t work.
set myLib to open thisScriptLibrary showing script dictionary
In the script below I still get a dialog asking if I want to open the library as a script or dictionary.
set scriptLibrariesFolder to path to library folder from user domain as text
set scriptLibrariesFolder to scriptLibrariesFolder & "Script Libraries:" as alias
tell application "Finder"
set myScriptLibraries to (the name of every file of scriptLibrariesFolder whose kind is "Compiled OSA Script Bundle") as alias list
end tell
--choose from list
set listTitle to "Script Libraries"
set listPrompt to "Which script dictionaries would you like to try to open?"
set OKButtonName to "These"
set multipleSelections to true
set emptySelectionAllowed to false
set userChoice to choose from list myScriptLibraries ¬
with title listTitle ¬
with prompt listPrompt ¬
OK button name OKButtonName ¬
multiple selections allowed multipleSelections ¬
empty selection allowed emptySelectionAllowed
if userChoice is false then return
set scriptList to {}
repeat with thisScript in userChoice
set the end of scriptList to ((scriptLibrariesFolder as text) & thisScript as text) as alias
end repeat
--repeat with thisScriptLibrary in userChoice
repeat with thisScriptLibrary in scriptList
tell application "Script Debugger"
set myLib to open thisScriptLibrary showing script dictionary
end tell
end repeat
return scriptList
One thing, though: without the bugs, you would end up with only the last script’s dictionary showing. That’s because the normal behavior of SD when you open a dictionary is that it replaces the dictionary that is already showing, if any. You probably need something like make new dictionary window in the loop, too.
And I don’t think you want that as alias list in there, although it doesn’t seem to do any harm.
(I only mention it because I was wondering why the script was taking a ridiculous amount of time to run. I mean, I know I probably have more libs than most people, but taking 13 seconds to find 50 .scptd files in a folder only containing 90? That’s truly appalling…)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set scriptLibrariesFolder to path to library folder from user domain as text
set scriptLibrariesFolder to POSIX path of (scriptLibrariesFolder & "Script Libraries:")
set thePaths to current application's NSFileManager's defaultManager()'s contentsOfDirectoryAtPath:scriptLibrariesFolder |error|:(missing value)
set thePaths to (thePaths's pathsMatchingExtensions:{"scptd"}) as list
Thanks, this is now in my handler collection and the script is in the SD Script menu! I may add a loop to check other library locations, but for now that’s the only folder I’m installing them in.
on GetFileNames(folderWithFiles, fileExtension)
set folderWithFiles to POSIX path of (folderWithFiles)
set thePaths to current application's NSFileManager's defaultManager()'s contentsOfDirectoryAtPath:folderWithFiles |error|:(missing value)
set fileNames to (thePaths's pathsMatchingExtensions:{fileExtension}) as list
return fileNames
end GetFileNames
and…
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set scriptLibrariesFolder to path to library folder from user domain as text
set scriptLibrariesFolder to scriptLibrariesFolder & "Script Libraries:"
set myScriptLibraries to my GetFileNames(scriptLibrariesFolder, "scptd")
set listTitle to "Script Libraries"
set listPrompt to "Which script dictionary would you like to try to open?"
set OKButtonName to "This One"
set multipleSelections to false
set emptySelectionAllowed to false
set userChoice to choose from list myScriptLibraries ¬
with title listTitle ¬
with prompt listPrompt ¬
OK button name OKButtonName ¬
multiple selections allowed multipleSelections ¬
empty selection allowed emptySelectionAllowed
if userChoice is false then return
set scriptList to {}
repeat with thisScript in userChoice
set the end of scriptList to ((scriptLibrariesFolder as text) & thisScript as text) as alias
end repeat
repeat with thisScriptLibrary in scriptList
tell application "Script Debugger"
set myLib to open thisScriptLibrary showing script dictionary
end tell
end repeat
on GetFileNames(folderWithFiles, fileExtension)
set folderWithFiles to POSIX path of (folderWithFiles)
set thePaths to current application's NSFileManager's defaultManager()'s contentsOfDirectoryAtPath:folderWithFiles |error|:(missing value)
set fileNames to (thePaths's pathsMatchingExtensions:{fileExtension}) as list
return fileNames
end GetFileNames