Tuesday, June 27, 2017

#1 2017-06-11 04:38:21 pm

artphotodude
Member
Registered: 2012-10-15
Posts: 43

Can't escape "\|" in Applescript...

Hi am creating a dynamic list based on names of volumes currently mounted and need to be able to append "\|" in-between each of the items, but there seems to be no way to escape it in Applescript.  If I add 2 backslashes, it works but then I wind up with "\\|" that doesn't work.  In fact, I can add as many even-numbered backslashes as I want, but none of them get me where I need to be.

Looking to create a string that looks like 'item1\|item2\|item3\|'  (then removing the final "\|" with a text line.

Any ideas??

Thanks!!

Offline

 

#2 2017-06-11 09:13:07 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2654

Re: Can't escape "\|" in Applescript...

artphotodude wrote:

If I add 2 backslashes, it works but then I wind up with "\\|" that doesn't work.  In fact, I can add as many even-numbered backslashes as I want, but none of them get me where I need to be.

There is a difference between the actual and presentation of a string. An escaped string is a string that is ready to be interpreted. So when you're in AppleScript like looking in the log, writing a static string or see the result you see an uninterpreted string. That means when you see "\\" the content is actually "\". A good way to see the difference between those two is using a display dialog.

Applescript:

set volumes to AST list volumes without showing invisibles

set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\\|"
set volumeString to volumes as string
set AppleScript's text item delimiters to oldTIDs

-- presentation of the string with single backslahes
-- you see the interpreted string here
display dialog volumeString

-- presentation of the same string in the result view with double backslahes
-- you see the uninterpreted string
return volumeString

p.s. the command AST list volumes is part of the AppleScript Toolbox.osax…

Offline

 

Board footer

Powered by FluxBB

[ Generated in 1.265 seconds, 12 queries executed ]

RSS (new topics) RSS (active topics)