afordturtle Posted August 23, 2020 Share Posted August 23, 2020 Hi. I'm trying to create a workflow that renames a folder on my desktop called "Catalog - Aaron Riddle Photography Template" to the current contents of my clipboard. I begin the workflow with a query to input. The input is copied to my clipboard contents. However, when I try to execute the following script to rename the folder, it doesn't work: mv '/Users/aaronriddle/Desktop/Catalog - Aaron Riddle Photography Template' '/Users/aaronriddle/Desktop/{query}' Note if I use that script and change the name of the file to a generic name, like "Test Folder", it works: mv '/Users/aaronriddle/Desktop/Catalog - Aaron Riddle Photography Template' '/Users/aaronriddle/Desktop/Test Folder' So is {query} the right thing to use here? Screenshot also attached. Thank you for any help you can provide!!! Link to comment
Dattwood Posted August 24, 2020 Share Posted August 24, 2020 (edited) Just tested this, and double quoting the second argument should fix the problem. Change your script object as follows (changing "[folder name]" to the target folder's name): mv "$HOME/Desktop/[folder name]" "$HOME/Desktop/{query}" Equivalently, if for whatever reason you change the script object's input tab to "with input as argv": query=$1 mv "$HOME/Desktop/[folder name]" "$HOME/Desktop/$query" Here's some information regarding quoting in bash: Quote 3.1. 2.2 Single Quotes Enclosing characters in single quotes (' ' ') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. 3.1.2.3 Double Quotes Enclosing characters in double quotes (' " ') preserves the literal value of all characters within the quotes, with the exception of ' $ ', ' ` ', ' \ ', and, when history expansion is enabled, ' ! '. When the shell is in POSIX mode (see Bash POSIX Mode), the ' ! Last note: "$HOME" is a special bash variable that automatically inserts your home folder into a double-quoted string. In general, be cautious when posting information that may identify you or your machine online. Edited August 24, 2020 by Dattwood clarification Link to comment
deanishe Posted August 24, 2020 Share Posted August 24, 2020 8 minutes ago, Dattwood said: Just tested it, and double quoting the second argument does fix the problem. Change your script object as follows: You should always use double quotes because Alfred doesn't offer the necessary escaping options to work correctly with single quotes. 9 minutes ago, Dattwood said: Equivalently, if for whatever reason you change the input tab to "with input as argv": Though “With input as argv” should always be preferred. It doesn’t have any of the issues {query} has. 10 minutes ago, Dattwood said: Please don't ever post your real home folder information online! It's hardly that much of an issue (especially on a client machine). @afordturtle already included his real name in his post. Link to comment
Dattwood Posted August 24, 2020 Share Posted August 24, 2020 2 minutes ago, deanishe said: It's hardly that much of an issue (especially on a client machine). @afordturtle already included his real name in his post. But good general advice to live by, no? Link to comment
deanishe Posted August 24, 2020 Share Posted August 24, 2020 22 minutes ago, Dattwood said: But good general advice to live by, no? Certainly, but you made it sound like it was really bad. I'm all in favour of putting the fear of God into people over information security, but when you say "don't ever do that" to something that isn't that big a deal, it doesn't leave you a whole lot of room to express how much worse things you genuinely should never do are (like post an API key online or save your login password in a script). You know what I mean? Link to comment
Dattwood Posted August 24, 2020 Share Posted August 24, 2020 I do. Edited the post. deanishe 1 Link to comment
afordturtle Posted August 24, 2020 Author Share Posted August 24, 2020 Wow thanks for the help! I appreciate it! One last question...how would I adjust the second argument to append a constant prefix (for instance "Job Log" to the front of the folder name prior to {query}? So if my query was "Test Folder"...it would create the folder as "Job Log - Test Folder". Something like this (which doesn't seem to work): mv "$HOME/Desktop/[folder name]" "$HOME/Desktop/Job Log - {query}" Link to comment
deanishe Posted August 24, 2020 Share Posted August 24, 2020 30 minutes ago, afordturtle said: Something like this (which doesn't seem to work): That's exactly how you should do it. When something doesn't work, check Alfred's debugger to see what's going wrong. And post the debugger output when you ask for help on the forum. Link to comment
afordturtle Posted August 24, 2020 Author Share Posted August 24, 2020 Here is the whole workflow I am trying to create. It works as follows: Takes an already created template folder, copies it to the Desktop, and renames it to the query with "Catalog - " in front of it. Then creates a new folder on the desktop with the query as the folder name, and four sub folders within. All of this works great, aside from when the template folder is created and renamed, it inserts "\" in front of where spaces appear in the query. Here is the workflow script...and also a screenshot showing it and the folder output below. In this example, the query "123 Test" was used. cp -a "$HOME/Dropbox (Personal)/Aaron Riddle Photography/Lightroom Settings/Catalog Templates/Catalog - Aaron Riddle Photography Template" "$HOME/Desktop/" mv "$HOME/Desktop/Catalog - Aaron Riddle Photography Template" "$HOME/Desktop/Catalog - {query}" cd $HOME/Desktop; mkdir {query}; cd {query}; mkdir Originals; mkdir Finals; mkdir Blog; mkdir Release; Link to comment
deanishe Posted August 24, 2020 Share Posted August 24, 2020 1 hour ago, afordturtle said: it inserts "\" in front of where spaces appear in the query You’re using incorrect Escaping options. Like I said earlier, don’t use {query}, use “with input as argv”. It’s much simpler and therefore much harder to screw up. Change it to "with input as argv" and use the following script: query="$1" cp -a "${HOME}/Dropbox (Personal)/Aaron Riddle Photography/Lightroom Settings/Catalog Templates/Catalog - Aaron Riddle Photography Template" "${HOME}/Desktop/Catalog - ${query}" mkdir -p "${HOME}/Desktop/${query}"/{Originals,Finals,Blog,Release} afordturtle and Dattwood 2 Link to comment
afordturtle Posted August 24, 2020 Author Share Posted August 24, 2020 Awesome. That works perfectly! Thank you for your help. Sorry...I'm a scripting newbie Link to comment
deanishe Posted August 25, 2020 Share Posted August 25, 2020 7 hours ago, afordturtle said: Awesome. That works perfectly! Thank you for your help. Sorry...I'm a scripting newbie Getting the Escaping options right for {query} is difficult for anyone, tbh. That's why argv was added. {query} can’t be removed for backwards-compatibility reasons, unfortunately. afordturtle 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