The workflow is:
1) Media offloaded from SD card to local Media Input folder
2) Hazel detects file type
3) Hazel runs AppleScript prompting user for existing project folder or create new project folder
4) Users input sent as folder location to Hazel for file processing.
5) Hazel does file processing.
I have this script compiled and working for the project folder location in the Apple script editor but when I past it into Hazel - Run Apple Script and select compile it throws and error. Expected “end” but found “property”.
Any ideas, I have reviewed the Hazel docs but it's not very clear if there are specific restrictions?
- Code: Select all
property defaultProjectsParentFolder : (path to documents folder as text) & "Projects:"
-- Ensure the default parent folder exists
tell application "Finder"
-- Check if the folder exists. If not, create it.
try
set defaultProjectsParentFolderAlias to (POSIX file (POSIX path of defaultProjectsParentFolder)) as alias
on error
-- Folder does not exist, so create it
make new folder at (path to documents folder) with properties {name:"Projects"}
set defaultProjectsParentFolderAlias to (POSIX file (POSIX path of defaultProjectsParentFolder)) as alias -- Get alias after creation
end try
end tell
set projectFolderPath to ""
-- Display a dialog to choose action
set dialogResult to display dialog "Do you want to select an existing project folder or create a new one?" buttons {"Select Existing", "Create New", "Cancel"} default button "Select Existing"
if button returned of dialogResult is "Select Existing" then
-- User wants to select an existing folder
try
set selectedFolder to choose folder with prompt "Select your project folder:"
set projectFolderPath to POSIX path of selectedFolder
on error
-- User cancelled folder selection
-- Return empty string for ProjectFolderPath to indicate cancellation
return {hazelOutputAttributes:{projectFolderPath:""}}
end try
else if button returned of dialogResult is "Create New" then
-- User wants to create a new folder
set newProjectNameResult to display dialog "Enter the name for the new project folder:" default answer "New Project" buttons {"OK", "Cancel"} default button "OK"
if button returned of newProjectNameResult is "OK" then
set newProjectName to text returned of newProjectNameResult
-- Construct the full path for the new project folder
set newProjectFolderPOSIXPath to (POSIX path of defaultProjectsParentFolder) & newProjectName
-- Create the new folder
try
tell application "Finder"
make new folder at defaultProjectsParentFolderAlias with properties {name:newProjectName}
set projectFolderPath to POSIX path of (newProjectFolderPOSIXPath as POSIX file)
end tell
on error errMsg
display alert "Error creating folder" message errMsg as critical
-- Return empty string for ProjectFolderPath on error
return {hazelOutputAttributes:{projectFolderPath:""}}
end try
else
-- User cancelled new project name entry
-- Return empty string for ProjectFolderPath to indicate cancellation
return {hazelOutputAttributes:{projectFolderPath:""}}
end if
else
-- User clicked Cancel on the initial dialog
-- Return empty string for ProjectFolderPath to indicate cancellation
return {hazelOutputAttributes:{projectFolderPath:""}}
end if
-- Return the projectFolderPath within the hazelOutputAttributes record
return {hazelOutputAttributes:{projectFolderPath:projectFolderPath}}