
But I'm going to learn how to use it properly from scratch. It's so useful.
Moderator: Mr_Noodle
tell application "System Events"
-- first get Finder selection
-- we always need that
tell application "Finder"
set Sel to selection -- a list of references - always!
set pSel to {} -- list to take POSIX strings
repeat with anItem in Sel
set anItem to anItem as alias as string -- coerce reference to alias, then string
set anItem to quoted form of POSIX path of anItem & space -- change to POSIX notation
set pSel to pSel & anItem -- add to list
end repeat
end tell
set pSel to pSel as string
-- now to find out what they want...
set TheChoice to (display dialog "Choose an Action" buttons {"Cancel", "Option 1", "Option 2"} cancel button "Cancel")
--... and do it
if button returned of TheChoice is "Option 1" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option1.workflow"
my doshell(pSel, workflowpath) -- do this
else if button returned of TheChoice is "Option 2" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option2.workflow"
my doshell(pSel, workflowpath) -- do that
end if
end tell
-- and a short subroutine to save even more lines
-- makes main script more legible
on doshell(theFiles, workflowpath)
set qtdworkflowpath to quoted form of POSIX path of workflowpath
set theCommand to "/usr/bin/automator -i " & theFiles & qtdworkflowpath
set output to do shell script theCommand
end doshell
tell application "System Events"
-- first get Finder selection
-- we always need that
tell application "Finder"
set Sel to selection -- a list of references - always!
set pSel to {} -- list to take POSIX strings
repeat with anItem in Sel
set anItem to anItem as alias as string -- coerce reference to alias, then string
set anItem to quoted form of POSIX path of anItem & space -- change to POSIX notation
set pSel to pSel & anItem -- add to list
end repeat
end tell
set pSel to pSel as string
-- now to find out what they want...
set TheChoice to (display dialog "Choose an Action" buttons {"Cancel", "Option 1", "Option 2"} cancel button "Cancel")
--... and do it
if button returned of TheChoice is "Option 1" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option1.workflow"
on doshell(theFiles, workflowpath)
set qtdworkflowpath to quoted form of POSIX path of workflowpath
set theCommand to "/usr/bin/automator -i " & theFiles & qtdworkflowpath
set output to do shell script theCommand
end doshell
else if button returned of TheChoice is "Option 2" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option2.workflow"
on doshell(theFiles, workflowpath)
set qtdworkflowpath to quoted form of POSIX path of workflowpath
set theCommand to "/usr/bin/automator -i " & theFiles & qtdworkflowpath
set output to do shell script theCommand
end doshell
end if
end tell
- copy the code of the subroutine, that's the lines between "on doshell.." end "end doshell".
tell application "System Events"
-- first get Finder selection
-- we always need that
tell application "Finder"
set Sel to selection -- a list of references - always!
set pSel to {} -- list to take POSIX strings
repeat with anItem in Sel
set anItem to anItem as alias as string -- coerce reference to alias, then string
set anItem to quoted form of POSIX path of anItem & space -- change to POSIX notation
set pSel to pSel & anItem -- add to list
end repeat
end tell
set pSel to pSel as string
-- now to find out what they want...
set TheChoice to (display dialog "Choose an Action" buttons {"Cancel", "Option 1", "Option 2"} cancel button "Cancel")
--... and do it
if button returned of TheChoice is "Option 1" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option1.workflow"
set qtdworkflowpath to quoted form of POSIX path of workflowpath
set theCommand to "/usr/bin/automator -i " & theFiles & qtdworkflowpath
set output to do shell script theCommand
else if button returned of TheChoice is "Option 2" then
set workflowpath to "Macintosh HD:Users:Jono:Documents:Automator Files:Option2.workflow"
set qtdworkflowpath to quoted form of POSIX path of workflowpath
set theCommand to "/usr/bin/automator -i " & theFiles & qtdworkflowpath
set output to do shell script theCommand
end if
end tell
set output to do shell script theCommand
do shell script theCommand
alastor933 wrote:I'm also not sure about doing dialogs in a Hazel script. From your description I gather that the error occurs AFTER the dialog closes. Right?
Mr_Noodle wrote:I'll try and check back in during the week but please excuse my relative absence during this time.