Tuesday, September 19, 2017

#1 2005-10-12 07:04:46 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

How can I create an empty file?

There are several ways to create an empty file using AppleScript. The quickest one is the following:

Applescript:

set newFilePath to "disk:folder:file.txt"
open for access file newFilePath
close access file newFilePath

The open for access command, from Standard Additions, will create a new file in the specified location if it doesn't exist.

From a shell script, you can also try this one:

Applescript:

do shell script "touch /path/to/file.txt"

And, finally, you can simply use the Finder:

Applescript:

tell application "Finder" to make new file at desktop

If you create a file using the Finder, you can also define some additional parameters. Eg:

Applescript:

tell application "Finder" to make new file at desktop with properties {name:"pic.jpg", creator type:"8BIM", comment:"Hi!"}


Filed under: Finder

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)