escaping :

Hi All.

I have a script that I setup and it works from terminal.

I need to create it into an application.

There is some punctuation in the script that I need to escape, but can not figure out how to get past it.


set SentItems to "Sent Items"

do shell script "/usr/libexec/PlistBuddy -c "delete :MailAccounts:2:SentMessagesMailboxName string" ~/Library/Preferences/com.apple.mail.plist"
do shell script "/usr/libexec/PlistBuddy -c "Add :MailAccounts:2:SentMessagesMailboxName string '$SentItems'" ~/Library/Preferences/com.apple.mail.plist"


Any help would be appreciated.

You can use “quoted form of” to add quotes to a string

do shell script "/usr/libexec/PlistBuddy -c " & quoted form of "delete :MailAccounts:2:SentMessagesMailboxName string" & " ~/Library/Preferences/com.apple.mail.plist"

Thanks a lot that did the trick.

you can also escape some characters by preceding them with a \

I have found some cases where you need to escape things twice, once in the AS layer and once in the shell, so you end up with double \

I generally always put my shell commands into a variable first, and then you can see what you are getting using a display dialog like this


set mailCmd to "/usr/libexec/PlistBuddy -c "Add :MailAccounts:2:SentMessagesMailboxName string '$SentItems'" ~/Library/Preferences/com.apple.mail.plist"

display dialog "mailCmd" default answer mailCmd

set mailCmdResult to (do shell script mailCmd)



sometimes it can be helpful to store the result of a do shell script, helpful to detect odd errors

just make sure to comment out the dialog before sharing your script

Why are you using plist buddy instead of defaults write?

Don

also,