Some handy handlers to give information about all folder actions.
It use ASObjC to be able to make dictionary. The ‘key’ is the name of folder action
So to get properties you need to know the key name.
use framework "Foundation"
use scripting additions
(**
* [allFolderActionsProperties()]
*)
-- set theNames to (its allFolderActionsProperties()'s allKeys()) as list
-- return (allFolderActionsProperties()'s valueForKey:"Volumes") as record
on allFolderActionsProperties()
set theDict to current application's NSMutableDictionary's dictionary()
tell application "Folder Actions Setup"
set folderActions to its name of folder actions
set theProperties to {}
repeat with anItem in folderActions
set end of theProperties to its properties of folder action (contents of anItem)
end repeat
repeat with i from 1 to (count folderActions)
(theDict's setObject:(item i of theProperties) forKey:(item i of folderActions))
end repeat
return theDict
end tell
end allFolderActionsProperties
(**
* [allScriptProperties()]
*)
-- set theNames to (its allScriptProperties()'s allKeys()) as list
-- return (allScriptProperties()'s valueForKey:"Volumes") as record
on allScriptProperties()
set theDict to current application's NSMutableDictionary's dictionary()
tell application "Folder Actions Setup"
set folderActions to its name of folder actions
set theProperties to {}
repeat with anItem in folderActions
set end of theProperties to its properties of script of folder action (contents of anItem)
end repeat
repeat with i from 1 to (count folderActions)
(theDict's setObject:(item i of theProperties) forKey:(item i of folderActions))
end repeat
return theDict
end tell
end allScriptProperties
(**
* [isFolderActionEnabled()]
*)
-- its isFolderActionEnabled()
on isFolderActionEnabled()
tell application "Folder Actions Setup" to folder actions enabled
end isFolderActionEnabled
(**
* [enableFolderAction(string folderActionName)]
*)
-- its enableFolderAction("Volumes")
on enableFolderAction(folderActionName)
tell application "Folder Actions Setup"
set folderActions to its name of folder actions
if folderActionName is in folderActions then
set enabled of folder action folderActionName to true
else
log "Check if folder action name is correct"
end if
end tell
end enableFolderAction
(**
* [disableFolderAction(string folderActionName)]
*)
-- its disableFolderAction("Volumes")
on disableFolderAction(folderActionName)
tell application "Folder Actions Setup"
set folderActions to its name of folder actions
if folderActionName is in folderActions then
set enabled of folder action folderActionName to false
else
log "Check if folder action name is correct"
end if
end tell
end disableFolderAction
(**
* [enableScriptFolderAction(string folderActionName)]
*)
-- its enableScriptFolderAction("Volumes")
on enableScriptFolderAction(folderActionName)
tell application "Folder Actions Setup"
set enabled of script of folder action folderActionName to true
end tell
end enableScriptFolderAction
(**
* [disableScriptFolderAction(string folderActionName)]
*)
-- its disableScriptFolderAction("Volumes")
on disableScriptFolderAction(folderActionName)
tell application "Folder Actions Setup"
set enabled of script of folder action folderActionName to false
end tell
end disableScriptFolderAction
And to enable/disable folder actions
(**
* [enableFolderActions()]
*)
-- its enableFolderActions()
on enableFolderActions()
tell application "Folder Actions Setup" to set folder actions enabled to true
end enableFolderActions
(**
* [disableFolderActions()]
*)
-- its disableFolderActions()
on disableFolderActions()
tell application "Folder Actions Setup" to set folder actions enabled to false
end disableFolderActions
And when we have the folder action script path we could tell Finder to open it for us.
(**
* [openActionFolder(string folderActionName)]
*)
-- its openActionFolder("TestFolder")
on openActionFolder(folderActionName)
tell application "Folder Actions Setup" to set thePath to ¬
POSIX path of script of folder action folderActionName
set theURL to current application's |NSURL|'s fileURLWithPath:(thePath as string)
set theFolder to (theURL's URLByDeletingLastPathComponent()) as string
tell application "Finder" to open theFolder
end openActionFolder
Some strange AppleEvents error I made this instead.
use framework "Foundation"
use framework "AppKit"
use scripting additions
(**
* [openActionFolderSetup()]
*)
-- its openActionFolderSetup()
on openActionFolderSetup()
set bundleID to "com.apple.FolderActionsSetup"
set workspace to current application's NSWorkspace's sharedWorkspace()
set theApp to workspace's URLForApplicationWithBundleIdentifier:bundleID
tell application "Finder" to open (theApp as string)
end openActionFolderSetup
And to enable/disable specific folderScriptName, instead of all folderScripts
(**
* [enableScriptFolderAction(string folderActionName,string folderScriptName)]
*)
-- its enableScriptFolderAction("Volumes", "Samsung Volumes.workflow")
on enableScriptFolderAction(folderActionName, folderScriptName)
tell application "Folder Actions Setup"
set enabled of script folderScriptName of folder action folderActionName to true
end tell
end enableScriptFolderAction
(**
* [disableScriptFolderAction(string folderActionName,string folderScriptName)]
*)
-- its disableScriptFolderAction("Volumes", "Samsung Volumes.workflow")
on disableScriptFolderAction(folderActionName, folderScriptName)
tell application "Folder Actions Setup"
set enabled of script folderScriptName of folder action folderActionName to false
end tell
end disableScriptFolderAction