Dollar signs in a file name mess up my script

I’m creating a script/AppleScript app to help an old man more easily create a new file.

The problem is that when a “$” is used in the title a file he creates with this new AppleScript (like “130 $100 asset.doc”) the name of his new file is set to “130 00 asset.doc”.

This applescript uses posix file names and shell scripts. How do I allow for “$” in filenames in shell?

On his old PC, he could right click and select “create new MS Word Doc” from the right-click menu. A new blank MS Word file would be created in the frontmost folder.

My approach was to create an app that he could open from his dock that would create a document with the name he specified in the frontmost folder.

Model: iMac
AppleScript: 2.3
Browser: Safari 537.71
Operating System: Mac OS X (10.8)

Since a quoted dollar is a special token in a shell script, I’d rather use Finder for creating the file, where a dollar sign hasn’t any significance anyway. The script below makes a new file in the Desktop folder.

set af to "Working for the Yankee $.txt"
tell application "Finder"
	make new file with properties {name:af}
end tell

Hi McUsr,

That’s exactly what I thought! :smiley:


If you need to use a shell script just quote the path

do shell script "touch " & quoted form of (POSIX path of (path to desktop) & "$$$.txt")


That works like a charm for me Stefan! :slight_smile:

I guess the trouble starts when you try to escape the dollar, but then again, an escaped dollar has just a special effect in some places. it works correctly in a terminal window at least, but it means newline when it is quoted within a script file, at least a sed script. :slight_smile:


An escaped dollar may also have a special meaning in a here document, at least in a here document you can specify an end of line by putting a "" at the end of it, (like in a sed script with the i a and c commands). -I think all the interpreters share some of the same guts, but it depends of course upon whether the input has been redirected or not. In this case with the straight forward use of a do shell script executing a command line, this doesn’t come into play. My bad.

Only when double quoted, when a string is quoted with single quotes it has no special meaning.

do shell script "echo \"$HOME\"" -->path to your user home folder
do shell script "echo '$HOME'" --> "$HOME"

That’s why I’m using quoted form of because it does always the right thing