I’m posting this script here because it’s kind of nifty, and there’s one part that’s not working and I can’t figure out why.
In short the script uses the “path to” Scripting Addition to figure out all the paths to special folders that can be opened at runtime, then provides the user a list (in Myriad Tables) of the good paths. The user can mark any of the paths as favorites, and can also select any of the paths. The ones selected will open in the finder. The ones marked favorites are the only ones that will be shown the next time the script is run. But the user will also have the option of generating a new list.
The part that doesn’t work is that when the user has picked favorites, but decides to generate the full list, the script forgets the favorites.
Here is where the script fails. FavoriteFolders is a property containing the user’s previous favorites.
If a path is in the FavoriteFolders list its first item will be true and it will display with a checkmark.
Instead, none of the items keep the checkmark.
if thisFolderInfo is in favoriteFolders then
set the end of workedPathsList to thisFolderInfo
else
set item 1 of thisFolderInfo to false
set the end of workedPathsList to thisFolderInfo
end if
Here’s the entire script:
use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib"
property favoriteFolders : {}
if favoriteFolders is {} then
set selectedFolders to my SelectAllFolders()
else
set selectedFolders to my SelectFromFavoriteFolders()
end if
tell application "Finder"
repeat with thisFolder in selectedFolders
set folderAlias to item 4 of thisFolder as alias
open folderAlias
end repeat
activate
end tell
on SelectFromFavoriteFolders()
set tableData to favoriteFolders
-- set table parameters
set tableTitle to "Open Folders"
set tablePrompt to "Select the folder(s) you would like to open"
set multipleSections to true
set addOrDelete to false
set editableColumns to {1}
set columnHeadings to {"Favorite", "Domain", "Decription", "Path"}
set rowNumbering to false
set initiallySelectedRows to {}
set emptySelectionAllowed to true
set rowTemplate to item 1 of tableData
set givingUpAfter to 600
--display table with data
set tableData to make new table with data tableData ¬
with title tableTitle ¬
with prompt tablePrompt ¬
multiple selections allowed multipleSections ¬
can add and delete addOrDelete ¬
editable columns editableColumns ¬
column headings columnHeadings ¬
row numbering rowNumbering ¬
initially selected rows initiallySelectedRows ¬
empty selection allowed emptySelectionAllowed ¬
row template rowTemplate
modify table tableData ¬
OK button name ¬
"OK" OK button is default true ¬
cancel button name ¬
"Cancel" extra button name ¬
"Select From Full List"
set tableResult to display table tableData ¬
giving up after givingUpAfter ¬
with extended results
set userButton to button number of tableResult
set selectedFolders to values selected of tableResult
set allFolders to values returned of tableResult
if userButton is 2 then
return SelectAllFolders()
end if
set favoriteFolders to {}
repeat with thisFolder in allFolders
if item 1 of thisFolder is true then
set the end of favoriteFolders to thisFolder as item
end if
end repeat
return selectedFolders
end SelectFromFavoriteFolders
on SelectAllFolders()
set allFolders to {apple menu, application support, applications folder, control panels, control strip modules, desktop, desktop pictures folder, documents folder, downloads folder, extensions, favorites folder, Folder Action scripts, fonts, help, home folder, internet plugins, keychain folder, launcher items folder, library folder, modem scripts, movies folder, music folder, pictures folder, preferences, printer descriptions, printer drivers, printmonitor, public folder, scripting additions folder, scripts folder, services folder, shared documents, shared libraries, shutdown folder, sites folder, speakable items, startup disk, startup items, stationery, system folder, system preferences, temporary items, trash, users folder, utilities folder, voices, workflows folder}
set allDomains to {user domain, system domain, local domain, network domain, Classic domain}
set allFoldersText to {"apple menu", "application support", "applications folder", "control panels", "control strip modules", "desktop", "desktop pictures folder", "documents folder", "downloads folder", "extensions", "favorites folder", "Folder Action scripts", "fonts", "help", "home folder", "internet plugins", "keychain folder", "launcher items folder", "library folder", "modem scripts", "movies folder", "music folder", "pictures folder", "preferences", "printer descriptions", "printer drivers", "printmonitor", "public folder", "scripting additions folder", "scripts folder", "services folder", "shared documents", "shared libraries", "shutdown folder", "sites folder", "speakable items", "startup disk", "startup items", "stationery", "system folder", "system preferences", "temporary items", "trash", "users folder", "utilities folder", "voices", "workflows folder"}
set allDomainsText to {"user domain", "system domain", "local domain", "network domain", "Classic domain"}
set workedPaths to {"Paths that worked"}
set failedPaths to {"", "Paths that failed"}
set workedPathsList to {}
set AppleScript's text item delimiters to {tab}
repeat with y from 1 to the count of allDomains
set thisDomain to item y of allDomains
repeat with x from 1 to count of allFolders
repeat 1 times
set thisFolder to item x of allFolders
set thisFolderString to item x of allFoldersText
set thisDomainString to item y of allDomainsText
try
set thisPath to path to thisFolder from thisDomain as alias
on error errMsg number errNum
set the end of failedPaths to {thisDomainString, thisFolderString, errMsg} as text
exit repeat
end try
set thisFolderInfo to {true, thisDomainString, thisFolderString, thisPath as text}
if thisFolderInfo is in favoriteFolders then
set the end of workedPathsList to thisFolderInfo
else
set item 1 of thisFolderInfo to false
set the end of workedPathsList to thisFolderInfo
end if
end repeat
end repeat
end repeat
set AppleScript's text item delimiters to {return}
{workedPaths, failedPaths} as text
-- set table data
set tableData to workedPathsList
-- set table parameters
set tableTitle to "Open Folders"
set tablePrompt to "Select the folder(s) you would like to open"
set multipleSections to true
set addOrDelete to false
set editableColumns to {1}
set columnHeadings to {"Favorite", "Domain", "Decription", "Path"}
set rowNumbering to false
set initiallySelectedRows to {}
set emptySelectionAllowed to true
set rowTemplate to item 1 of tableData
set givingUpAfter to 600
--display table with data
set tableResult to display table with data tableData ¬
with title tableTitle ¬
with prompt tablePrompt ¬
multiple selections allowed multipleSections ¬
can add and delete addOrDelete ¬
editable columns editableColumns ¬
column headings columnHeadings ¬
row numbering rowNumbering ¬
initially selected rows initiallySelectedRows ¬
empty selection allowed emptySelectionAllowed ¬
row template rowTemplate ¬
giving up after givingUpAfter
set selectedFolders to values selected of tableResult
set allFolders to values returned of tableResult
set favoriteFolders to {}
repeat with thisFolder in allFolders
if item 1 of thisFolder is true then
set the end of favoriteFolders to thisFolder as item
end if
end repeat
return selectedFolders
end SelectAllFolders
I plan to add to this the paths to the various script library folders; paths to the various application scripts folders; paths to scripts folders for applications in the Scripts menu.
Any suggestions welcome