Making a file in the preferences folder

I need to make a file called “Example.txt” in Library/Preferences directory. I don’t need anything to be in it, I just need to make it. How could I do that?

Maybe like:


make file Example.txt in directory Library/Preferences

Try something like this:

do shell script "/usr/bin/touch -a " & quoted form of POSIX path of ((path to preferences folder as Unicode text) & "Example.txt")

or this (assuming you really meant /Library/Preferences and not ~/Library/Preferences)

set P to path to preferences folder from local domain
set ET to open for access (P as text) & "Example.txt"
close access ET

I can’t think why anyone would want to script the creation of a file in /Library/Preferences rather than in ~/Library/Preferences. However, the File Read/Write commands are much faster than a shell script and could be condensed into one line so:

close access (open for access file ((path to preferences folder as Unicode text) & "Example.txt")) -- In the user's Preferences.

Or, if really necessary:

close access (open for access file ((path to preferences folder from local domain as Unicode text) & "Example.txt")) -- In the local Preferences.

I’d like to repeat: using user defaults in your Xcode project would be so much better and easier :slight_smile: