creating empty file


How can I tell applescript, if file “.hiddenfile” does not exist then create file?


Not an awful method. There are ways you could do it with “do shell script”, but this works well for most situations. (Your specific needs may vary. You may want to tweak the error handling a bit to be more specific.)

And we have still one more FAQ called “How can I create an empty file?”:

From this FAQ:

cat > /path/to/file.txt

Hmm. Do this instead:

touch /path/to/file.txt

See also:

Yes, but anyway, the interesting and faster approach is the “open for access method” (at least in AS). “do shell script” calls in this topic should be slower, as you are invoking the scripting addition, then “touch”, “cat” or whatever.

Actually, “open for access” and “do shell script” are both in Standard Additions. However, you forgot that “do shell script” starts a shell, which then runs the script. Thus, a typical “do shell script” command involves two external processes. (Adding a few pipes easily boosts this to 4+ external processes.)

Yes, that’s why “open for access” is faster (it doesn’t need extra processes such as “touch” to accomplish the task, appart from the great slow-down with “do shell script” in Tiger, as recently commented in various AS sources) :smiley:

Perhaps it is faster, but if I’m more familiar with the shell, then that’s probably what I’ll use. For example, I recently used this script to replace text in an existing file.

do shell script "perl -i -p -e 's:" & find & ":" & replace & ":' " & quoted form of (output & webName & ".html")

I don’t care much about the speed for this part, because the “longest” wait in my script comes from converting pictures to a smaller size (using ImageMagick).

Yes, speed is irrelevant when we talk about milliseconds if your task is a long one :wink: