Jump to content
Sign in to follow this  
tsf

Escape single quotes in run script/script filter

Recommended Posts

Quite a lot of the scripts I run in Alfred involve handling multiple files (i.e. {query} is a list of tab-separated files). Without some relatively complex code (bash doesn't make it easy) that obfuscates the purpose of the script, they all break with files containing apostrophes. It would be very useful if there were an option to escape single quotes, like you can with double quotes.

Share this post


Link to post
Share on other sites

Quite a lot of the scripts I run in Alfred involve handling multiple files (i.e. {query} is a list of tab-separated files). Without some relatively complex code (bash doesn't make it easy) that obfuscates the purpose of the script, they all break with files containing apostrophes. It would be very useful if there were an option to escape single quotes, like you can with double quotes.

 

Would the following code not be sufficient? This will code will split the string base on a tab (alfred's delimiter) and create an array of the file names. It even works with file names that contain single quotes.

query="~/Downloads/file1.txt		~/Downloads/file2.txt	~/Downloads/file3.txt"
IFS="	" read -ra files <<< "$query"
for file in ${files[@]}; do
	echo $file
done

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...