MattRodkey Posted June 12, 2014 Share Posted June 12, 2014 Hi, I have created a workflow that I trigger from Hazel so that a newly downloaded file pops up into Alfred. Ideally what I would like to do with many of these files is 1) Move them to a new location 2) Open them. Is this possible? I am guess that the answer is yes somehow, but I just can't seem to find it yet. Link to comment
chadv Posted June 12, 2014 Share Posted June 12, 2014 (edited) One way would be to use a script. Here's a bash script you can use with the Run Script action: # extract the filename from a full path filename=$(basename "{query}"); # set the new destination destination="/your/new/path/$filename"; # move the file mv "{query}" $destination; # open it open $destination; Edited June 12, 2014 by chadv Link to comment
MattRodkey Posted June 12, 2014 Author Share Posted June 12, 2014 Thanks that is a good start. I want to be able to select the destination every time so I tweaked your script to add some AppleScript for selecting a directory. # extract the filename from a full path filename=$(basename "{query}"); # set the new destination newpath=`osascript -e 'set theFolderAlias to choose folder' -e 'set theFolder to (the POSIX path of theFolderAlias)'` destination="$newpath/$filename"; # move the file mv "{query}" $destination; # open it open $destination; osascript -e 'set theFolderAlias to choose folder' -e 'set theFolder to (the POSIX path of theFolderAlias)' One way would be to use a script. Here's a bash script you can use with the Run Script action: # extract the filename from a full path filename=$(basename "{query}"); # set the new destination destination="/your/new/path/$filename"; # move the file mv "{query}" $destination; # open it open $destination; Link to comment
MattRodkey Posted June 12, 2014 Author Share Posted June 12, 2014 This works like a charm. Thanks for the help. One thing to note in the paste of code in my line above I accidentily added the osascript line a second time at the bottom. The real code should look like: extract the filename from a full path filename=$(basename "{query}"); # set the new destination newpath=`osascript -e 'set theFolderAlias to choose folder' -e 'set theFolder to (the POSIX path of theFolderAlias)'` destination="$newpath/$filename"; # move the file mv "{query}" $destination; # open it open $destination; chadv 1 Link to comment
jdfwarrior Posted June 13, 2014 Share Posted June 13, 2014 Thanks that is a good start. I want to be able to select the destination every time so I tweaked your script to add some AppleScript for selecting a directory. # extract the filename from a full path filename=$(basename "{query}"); # set the new destination newpath=`osascript -e 'set theFolderAlias to choose folder' -e 'set theFolder to (the POSIX path of theFolderAlias)'` destination="$newpath/$filename"; # move the file mv "{query}" $destination; # open it open $destination; osascript -e 'set theFolderAlias to choose folder' -e 'set theFolder to (the POSIX path of theFolderAlias)' If you wanted to get really fancy... You could... Let hazel pick up the file, then Hazel would use AppleScript to.. tell application "Alfred 2" to search "<full path to file>" That would bring up Alfred in file browser with that file selected, then you would have the option to run any action on it. To continue though, you could have a custom "move and open" action. Then, save the file name in a temp place, use external triggers to hit a next step in the workflow that is a file filter that would only show folders so you could search for the folder to move to, when you press enter, it moves to that folder, then opens the file. Ya know... if you wanted to get fancy.. hehe chadv 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now