Re: New plist File
Re: New plist File
- Subject: Re: New plist File
- From: Axel Luttgens <email@hidden>
- Date: Thu, 3 Feb 2011 00:20:16 +0100
Le 2 févr. 2011 à 19:14, Luther Fuller a écrit :
> In the past, there has been comment on the inability of System Events to make a new property list file. I have been using 'do shell script "defaults write " & ... ' to do this, but wanted to find another way.
Hello Luther,
Not sure whether relevant, but this seems to already have been solved here, as witnessed by this one:
Le 1 avr. 2010 à 10:26, Axel Luttgens a écrit :
> Le 1 avr. 2010 à 02:46:42, Shane Stanley a écrit :
>
>> On 1/4/10 11:42 AM, "Luther Fuller" <email@hidden> wrote:
>>
>>> I still suspect that System Events does not know a property list file from a
>>> trash icon.
>>
>> It knows them and can read and modify them; it just can't seem to create
>> them.
>
> Hello Shane,
>
> Well, this already has discussed on the list; see for example:
>
> http://lists.apple.com/archives/applescript-users/2008/Jan/msg00396.html
>
> Assuming one wants to create a plist with an array of numbers, here's a sample incantation:
>
> tell application "System Events"
> set PLItem to make new property list item with properties {value:{1, 2, 3}}
> set PLFile to make new property list file with properties {name:"~/Desktop/test.plist", contents:PLItem}
> end tell
>
> The ability for System Events to create property list files came with Leopard.
To be sure, I just tried above script on a nowadays 10.6.6, and it still works as intended.
So, let's go on.
> Yesterday, I Googled "property list file" and found some interesting results. This lead to this handler ...
>
> on makeNewPlistFile(folderAlias, filename, initialRecord)
> set newFileName to (folderAlias as text) & filename & ".plist"
> tell application "System Events"
> make new property list item with properties {kind:record, value:initialRecord}
> make new property list file with properties {contents:the result, name:newFileName} --> «class plif» "/Users/lutherfuller/Desktop/TEST_FILE.plist"
> end tell
> end makeNewPlistFile --------------------------------------------------------------------
> -- folderAlias is an alias to the location where the new file is created
> -- filename is text, the name of the new file without ".plist"
> -- initialRecord is an AppleScript record which becomes the content of the new file
Hmm... Here, we get divergent results. With "my" code, the result log shows:
property list file "/Users/luttgens/Desktop/test.plist"
not:
«class plif» "/Users/luttgens/Desktop/test.plist"
Some addition at work?
> It works very well, but I would like it to return an alias to the new file.
> That is, return the last line as an alias.
>
> This seems impossible to do. Neither System Events nor the Finder nor anything else seems to know what a «class plif» is. All I can get is an error message. It is impossible to convert this to an alias, a posix path, a text path or a reference.
>
> Does anyone know what's happening here?
This one works very well here:
tell application "System Events"
set PLItem to make new property list item with properties {value:{1, 2, 3}}
set PLFile to make new property list file with properties {name:"~/Desktop/test.plist", contents:PLItem}
alias (path of result)
end tell
--> alias "Boot:Users:luttgens:Desktop:test.plist"
Beside some interfering scripting addition, I don't have a clue.
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden