Jump to content

Hotkey with Text Selection in OS X fails if text has an apostrophe


Recommended Posts

I spend a few hours trying to figure out why sometimes my workflow does not work with AppleScript Editor.

 

By the way, my workflow is simple:

 

1. select a text in AppleScript Editor

2. press the workflow hotkey (argument: text selection in OS X)

3. my workflow grabs the text from the clipboard, saves it in a text file and tags it with  “AppleScript_Editor" using openmeta

 

newfiletag.png

 

However, I have found that if the text/code has an apostrophe the workflow fails. Sample code that does not work with my workflow:

 

--Search and replace string
set theApp to " AppEdit Editor ,loc, bolo "
set theApp to switchText from theApp to "" instead of " "
return theApp
to switchText from t to r instead of s
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	tell t to set t to item 1 & ({""} & rest)
	set text item delimiters to d
	t
end switchText

 

If I select the text here I can use my workflow but in AppleScript Editor I can't. If I remove that single line with the apostrophe the workflow works.

 

Note that the issue happens only when the hotkey is used.

 

I have tested all code in AppleScript Editor and there’s no error. The text is processed perfectly.

 

Here is the workflow that is set to my Dropbox Notes folder and requires openmeta (link inside the add.scpt file). However, you can set any folder and remove the openmeta code (I have tested the workflow without it).

 

 

 
There are some unnecessary bits of code that I wrote trying to debug...
 
NOTE: if I remove {query} from the Run Script (though I need it for the keyword) the hotkey works and thus the workflow. So there’s is an issue regarding {query}  and apostrophe.
 
 

 

Link to comment

There are some unnecessary bits of code that I wrote trying to debug...

 
NOTE: if I remove {query} from the Run Script (though I need it for the keyword) the hotkey works and thus the workflow. So there’s is an issue regarding {query}  and apostrophe.

 

' will interpreted in bash as a command, so have you tried changing your bash script to:

 

osascript add.scpt "{query}"

 

and then turning off all of the escaping options above the script apart from double quotes?

Link to comment

' will interpreted in bash as a command, so have you tried changing your bash script to:

 

osascript add.scpt "{query}"

 

and then turning off all of the escaping options above the script apart from double quotes?

 

I made a test and it worked.

 

Thank you for your help! 

Link to comment

Hey Carlos, I messaged you but if we could get a copy of this workflow that would be great. I love the premise, it just has a couple of weird quirks at the moment for me... Thanks bud!

 

I have just sent you a link with the current “alpha” version.

 

As I wrote to you, I ended up making one script for each action and it is working a lot better.

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