Jump to content

[SOLVED] Can file action escape path names?


Recommended Posts

Hi,

I'm trying to create a workflow that can copy paths for later use.

Frist I create a new workflow and add a file action to it that accepts multiple lines

then I enter a copy to clipboard module that says {query}

I run this script by selecting 2 files and double tap the command key and choose my test script

and I paste it textedit

the result:

/temp/test 1/MapA/test (2).JPG
/temp/test 1/MapA/test (1).JPG

 

the thing is when I drag the 2 files to a terminal window I get this:

/test\ 1/MapA/test\ \(1\).JPG /test\ 1/MapA/test\ \(2\).JPG 

filenames are separated by a space and the filenames are escaped

 

is there a script that can do this to?

so when I select files it copy's the full pathnames escaped and separated by a space?

Edited by Raffie77
typo
Link to comment
1 hour ago, Raffie77 said:

is there a script that can do this to?

 

You can write one easily enough. Python 2 has pipes.quote() (shlex.quote() in Python 3) to escape a string in the way a shell expects. I’m sure other languages have the same.

 

Buuuut …

 

1 hour ago, Raffie77 said:

I'm trying to create a workflow that can copy paths for later use.

 

What do you mean by this?

 

If you copy the files to the clipboard (i.e. select them in Finder and hit ⌘C), you’ll have NSFilenamesPboardType on the clipboard, and the files will then paste correctly (i.e. already escaped) into Terminal/iTerm. In a way, you’re causing the issue yourself by converting the files into plain, old paths.

 

You might have more luck with a tool that understands multiple files, like Dropshelf, which lets you drop multiple files onto a, well, shelf for later use.

Link to comment
2 minutes ago, deanishe said:

What do you mean by this?

i want to create a script for exiftool

so I want to select those files that I want to rename and copy this to the clipboard:

exiftool -d "%Y-%m-%d %H,%M,%S%%-c" '-filename<${DateTimeOriginal} $Make-$Model.%e' {multiple files that are decent escaped}

 

6 minutes ago, deanishe said:

You can write one easily enough. Python 2 has pipes.quote() (shlex.quote() in Python 3) to escape a string in the way a shell expects. I’m sure other languages have the same.

ok I never worked with python i'll look into that

I see that I can run a Pythons script in Alfred workflow

 

Thanks

Link to comment
1 hour ago, vitor said:

 

ooohhh shoot, you're right

I tweaked the script a bit and it almost works

the link that you are refering to is ment for one single file.

when I select multiple files in my new script, only one gets renamed

how can I make it happen that he renames all the files I select and not just one?

Do I need to convert a array or something?

Link to comment
2 hours ago, Raffie77 said:

how can I make it happen that he renames all the files I select and not just one?

 

Do something like

exiftool <your parameters here> "${@}"

or

for file in "${@}"; do
  exiftool <your parameters here> "${file}"
done

if it needs to run once for each file.

Link to comment

I also add a keyword in alfred in cas I want to add an extra name like "flower" of "tree" etc.

in the script i have this:

${exiftool} -d "%Y-%m-%d %H,%M,%S%%-c" '-filename<${DateTimeOriginal} $Make-$Model "${keyname}".%e' "${files}"

If I enable the debug mode I get this message:

Quote

Warning: [minor] Tag 'keyname' not defined - /Volumes/Ext 1TB/Google Drive/temp/test 1/MapA/243.jpg

 

The "$keyname" is a var that I created in Alfred see screenshot, the first var is the "$files" and the second var = "$keyname"

in te script I used "$keyname" with the purpose to enter the text that I typ in Alfred, but Exiftool thinks that "$keyname" is a Exiftool code and that's not the case hence the error

well single and double quotes and escaping are not my strong suite. 

Do I need to escape something here or split up the quotes ore something like that?

 

btw this code below works great (without the $keyname):

${exiftool} -d "%Y-%m-%d %H,%M,%S%%-c" '-filename<${DateTimeOriginal} $Make-$Model.%e' "${files}"

 

 

Schermafbeelding 2020-05-02 om 12.11.07.png

Edited by Raffie77
Link to comment
5 hours ago, Raffie77 said:

Do I need to escape something here or split up the quotes ore something like that?

 

Don’t fixate on escaping. None of the issues on this thread are related to it. Keep it out of your mind, as it may be preventing you from seeing the real problem.


In this case, the likely issue is that you’re throwing your files argument out of the window when you stick the Keyword in there. See LabelColor for a way to do what you want.

 

In the future, when asking for help with a Workflow, please upload it somewhere as screenshots of how you’ve connected things aren’t usually enough to debug an issue.

Link to comment

ok

I have a link to this workflow in my dropbox

you can download it here

 

yes I found your labelcolor workflow, I learned from that how to add a keyword in the file action.

I hope you can take a look at this workflow.

I'm not sure what I am missing here

Link to comment

vitor:

thank you very very very much🙌

it works!

I nerver heard of/used 

IFS=$'\t'

so i read into that, now I understand

I tested this and it still didn't work, the issue is, in this line:

${exiftool} -d "%Y-%m-%d %H,%M,%S%%-c" '-filename<${DateTimeOriginal} $Make-$Model "${1}".%e' "${files[@]}"

The "${1}" in this line doesn't work, if you take a look at $Make-$Model that means that Exiftool gets the value of the make and the model.

"${1}" is not a Exiftool value, but Exiftool is reading this as a Exiftool value and that value doesn't exist.

 

so for people who wants to know how to fix this?

this is the working code:

IFS=$'\t' read -ra files <<< "${file_list}"

${exiftool} -userparam extName="${1}" -d "%Y-%m-%d %H,%M,%S%%-c" '-filename<${DateTimeOriginal} $Make-$Model $extName.%e' "${files[@]}"

Exiftool has a option -userparam here you can create a user parameter in my case called extName (extra name)  and I used that later on after the $Make-$Model

 

I have the working version here 

Link to comment
  • vitor changed the title to [SOLVED] Can file action escape path names?

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...