Re: "Quoted form" puzzlement
Re: "Quoted form" puzzlement
- Subject: Re: "Quoted form" puzzlement
- From: Laine Lee <email@hidden>
- Date: Wed, 10 Nov 2010 13:23:51 -0600
- Thread-topic: "Quoted form" puzzlement
I think quoting in AppleScript requires a strategy rather than a solution.
One of my favorite scripting methods involves compiling on the fly using
osascript. For example, it's much easier for me to use the AppleScript
method for mounting network shares than to determine all the information
needed to do that using a shell script:
osascript -e "mount volume \"https://one.place.of.mine/personal/me\""
Or I can use osacompile to convert any script I've saved in text format into
a script as shown in the following example.
osacompile -o ~/Desktop/afile.scpt ~/Desktop/afile
I've said this before, but if I didn't use Smile for anything else, I would
use it so I could convert text to AppleScript strings with a single
keystroke (⌘⇧')
Sometimes I embed a script in too many layers for that simple operation to
be effective. Under those circumstances, I have usually found it effective
to start with the string conversion in Smile, and then to add backslashes
where I see that backslashes have been already been added by that operation,
one at a time between compile attempts, until I get enough to allow
compilation and to produce the intended results. Sometimes meeting both
those requirements is challenging, but it's often possible to extract a
small part of the script without changing the layer level of the target code
so that that section can be tested.
Laine Lee
On 11/10/10 12:18 PM, "Rob Lewis" <email@hidden> wrote:
> When I enter this in script editor:
>
> set x to "/a/b/c/Jack's trip.jpg"
> quoted form of x
>
> I get this:
>
> "'/a/b/c/Jack'\\''s trip.jpg'"
>
> Disregarding the main enclosing double quotes (which always appear when the
> editor displays a string value), and parsing the backslashes, this should
> translate to this, right?
>
> '/a/b/c/Jack'\"s trip.jpg'
>
> Am I missing something? I can't make any sense out of this, and I doubt it
> would work as a valid POSIX path. And how did that double quote get stuck in
> the middle of the string?
>
> Now try the same code in a "Run AppleScript" block in Automator:
>
> on run {input, parameters}
>
> set x to "/a/b/c/Jack's trip.jpg"
> return quoted form of x
> end run
>
> Guess what gets returned. This:
>
> '/a/b/c/Jack'\''s trip.jpg'
>
> which is the same as my "decoded" form of Script Editor's result, but still
> doesn't make any sense that I can see.
>
> It seems to me the correct encoding should be this:
>
> '/a/b/c/Jack\'s trip.jpg'
>
> Am I wrong? What does it all mean?
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> edu
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
_______________________________________________
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