Jump to content

Compound File Actions (move and then open) Possible?


Recommended Posts

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

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 by chadv
Link to comment

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

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;

Link to comment

 

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

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...