Jump to content

Replicate "copy to..." or "move to..." file actions from workflow?


Recommended Posts

Hello,

 

I'm trying to create the ability to mirror the actual workflow aspect of the file actions "Copy to..." and "Move to...."  Specifically, I want to be able to:

 

1. Select a file, or multiple files, through Alfred's file buffer or in the Finder.

2. Trigger Alfred's "File Actions" menu.

3. Select my workflow action from the list.

4. Choose a target folder, using Alfred's search (or even better, using Alfred's "browse" feature, but that's not how "Copy to..." works).

5. Run an action (e.g. shell script) on the selected files, with the "target folder" available in some fashion as well.

 

The specific use case I have is to enable the creation of aliases, symlinks, or hard links in a specified location for the selected files.

 

However, I haven't been able to figure out how to link together actions in a way that allows this.  Saving the query to a var is confusing, because it's not clear how multiple selected files can be saved in that way.  Then, I can't figure out which "action" to choose to allow searching for a folder (preferably with the selected files still shown in the pane to the right, just like they are in "Copy to..." and "Move to...").

 

Can someone provide some tips or a nudge in the right direction, please?

 

Thanks very much,

--Mike

Link to comment

To save multiple files (or multiple anything else) to a workflow variable, you'll need to encode them as JSON (or some other string) first, so they can be passed as one variable. JSON is a good fit, or you can join the paths with colons, like PATH, or join them with newlines etc.

 

Alternatively, you could set a bunch of variables, e.g. PATH_1, PATH_2, PATH_3 etc.

 

That would probably mean implementing your own folder search for the destination, however.

 

Alternatively, you could save the paths to a temporary cache file, then add another File Action for "My Workflow Target" which loads the paths from the cache and performs whatever action on them.

 

The issue there is that it's hard-to-impossible to enforce that your "My Workflow Target" File Action is called with freshly-selected paths. Best you can probably do is to delete the cache file if it's too old (or ask for confirmation of the paths).

Link to comment

The only illegal character in a file path is a null byte.  No other delimiter is guaranteed not to appear in the path.  (Related: Why not parse the output of ls?)  Particularly when dealing with music files, there are all kinds of unusual characters that quite commonly appear in filenames.

 

Perhaps what I want should simply be a native feature of Alfred?  It could be disabled for those who don't want it, just as any other built-in file action—but I'm sure I'm not the only one who would have a use for creation of aliases, symlinks and hard links through Alfred's excellent File Actions interface.

 

If the clean and smooth "Copy to..." and "Move to..." workflows (in the English sense) are impossible to replicate with a user defined workflow (in the Alfred sense)...I expect they'd be fairly trivial to add in the underlying code, starting from a replica of the "Copy" and "Move" file actions. :)

 

I just upgraded to Alfred 3 today and got my Mega Supporter license.  Hoping I won't have to use some other tool, e.g. Path Finder or something, to make this workflow possible....

Link to comment
12 minutes ago, Wildcard said:

The only illegal character in a file path is a null byte.  No other delimiter is guaranteed not to appear in the path.  (Related: Why not parse the output of ls?)  

 

Yeah. That only applies to Linux file systems, where filenames are bytes.

 

On HFS+, filenames are all UTF-8 (normalised to NFD, nearly). Both using JSON and setting multiple variables, which I previously mentioned, would work.

 

12 minutes ago, Wildcard said:

I just upgraded to Alfred 3 today and got my Mega Supporter license.  Hoping I won't have to use some other tool, e.g. Path Finder or something, to make this workflow possible....

 

It is perfectly possible as I described. Just clunky and error prone compared to a native File Action…

Edited by deanishe
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...