backslash in applescript variable

I've a windows file path which uses backslashes and I want to add to a variable but applescript will not treat the slash as a text character. I want to pass to the variable from the clipboard and replace with the forward slashes so I can use the go to folder in finder. The windows file path is not always the same, so I can't manually edit to a double backslash. thanks

Posted on Jul 5, 2011 4:17 PM

Reply
8 replies

Jul 5, 2011 4:45 PM in response to John H

Applescript strings use the backslash as an escape character (mostly for quotes, so that you can have a command like set bob to "he said\"Wow!\"" which includes the quote character. In most cases applescript will quote this for you, for instance if you copy a backslashed path onto the clipboard and use a command like set txt to the clipboard, applescript will get a properly escaped version of the string from the clipboard. about the only time you will ever see this backslash problem is when you manually type a backslash into an applescript string. just type \\ anywhere you would normally type \. or instance, to pass a window's string to the clipboard, use something like the following


set the clipboard to "C:\\user\\docs\\Letter.txt"


It looks a little odd, but you get used to it. 😝

Nov 6, 2014 6:25 AM in response to Niel

How would you do this with the following applescript code (which causes a syntax error: selection of {application "Finder", "\""} can't be transformed into text type):


tell application "Finder" & quote

set sel to the selection as text


set the clipboard toPOSIX path of sel

end tell

end tell

My goal is to create a automator workflow using applescript which copies the path of a finder object to the clipboard. In Yosemite.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

backslash in applescript variable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.