On the difficulties of "/"" in Applescript with example
On the difficulties of "/"" in Applescript with example
- Subject: On the difficulties of "/"" in Applescript with example
- From: Walter Bushell <email@hidden>
- Date: Thu, 17 Oct 2013 10:30:32 -0400
Given the difficulties encountered in merely escaping quotes is it perhaps better to replace them with an arbitrary sequence, for example "!xyzzy!" and change them when it's time to actually use them. What happens with quotes is the slashes disappear in the course of normal use.
We have to use some method to handle this as we have no choice but to handle every string our (ab?) users thrust upon us. I ran in this problem when presented with "Haydn: String Quartet In C, Op. 33/3, H 3/39, "Bird" - Allegro Moderato" which is illegal as an AppleScript construction. Perhaps fortunately as I would not have thought about that case, probably.
++++++++++++++++Code follows.
-- simple case works no quotes in file name
set x to POSIX file "/Users/Walter/Music/ur file"
tell application "Finder" to set B to name of file x
log B
log "+++++++++++++++++++++++++++"
-- merely once escaped quotes fail
try
set x to POSIX file "/Users/Walter/Music/\"ur\"file"
log x
tell application "Finder" to set B to name of file x
--log {"B quoted= ", b}
on error erorrStr number errnum
log {erorrStr, errnum}
end try
-- but passing an extra "\" does
try
-- put in an extra (escaped \) and it runs
set x to POSIX file "/Users/Walter/Music/\\\"ur\\\"file"
log x
tell application "Finder" to set B to name of file x
log {"B quoted and extra Slashed= ", B}
on error erorrStr number errnum
log {erorrStr, errnum}
end try
-----------------------Events & Replies ---------------------
--
"... the heavy people know some magic that can make things move and even fly,
but they're not very bright, because they can't survive without their magic contrivances" -- Xixo, in "The Gods Must Be Crazy II"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden