I’ve been pondering about a little script I made for the past hours or so. I just can’t get it to work, even though it is so darn simple. Here goes the script:
set libraryFolderPath to path to library folder from user domain
set libraryFolderPath to libraryFolderPath as text
set plistPath to libraryFolderPath & "Preferences:com.apple.itunes.plist"
alias plistPath -------> The path can be aliased with no problem. it exists. :-D
open for access file plistPath
set fileContents to (read plistPath) -------> this line causes the error.
close access plistPath
The script fails at the line indicated with the message:
Can't make \"Macintosh HD:Users:Max:Library:Preferences:com.apple.itunes.plist\" into type file.
Any reason why this is not working? Is it cause I am trying to read from a string rather than POSIX?
Thanks for any help.
Try something like this:
set fileContents to read alias ((path to preferences folder as Unicode text) & "com.apple.itunes.plist")
However, you’ll probably end up with some binary content that way.
Thanks worked like a charm.
PS: Yes, indeed, it’ll give me the contents in binary. But for the script I’ve written, I am just checking if a certain defaults entry is there. So I just have to search the file for the object key name (and the name stays the same in binary). Though, thanks for pointing it out.
to check a key of a preference file, you can use this routine
CheckKey for "Hello" from "com.apple.iTunes" --> false
CheckKey for "tvShowsLimit" from "com.apple.iTunes" --> true
on CheckKey for k from d
do shell script "/usr/bin/defaults read " & d & space & k
-- key doesnt exist
or in AppleScript Studio user defaults is directly scriptable
I had something where I’d see if the file contains “theKey.” It wasn’t the best of it:
if fileContents contains "theKey" then
Though, your solution is quite interesting and I am actually going to use it cause I love the shell commands. They are way faster and have shorter code.