Send AppleScript-Users mailing list submissions to
email@hiddenTo subscribe or unsubscribe via the World Wide Web, visit
https://lists.apple.com/mailman/listinfo/applescript-users
or, via email, send a message with subject or body 'help' to
email@hidden
You can reach the person managing the list at
email@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of AppleScript-Users digest..."
Today's Topics:
1. Re: Problem saving a new file (Eric Robertson)
2. Re: Problem saving a new file (Eric Robertson)
----------------------------------------------------------------------
Message: 1
Date: Sat, 20 Oct 2012 17:37:27 +0100
From: Eric Robertson <email@hidden>
To: email@hidden
Subject: Re: Problem saving a new file
Message-ID: <
email@hidden>
Content-Type: text/plain; charset="windows-1252"
Le 19/10/2012 à 15:54, Eric Robertson <email@hidden> a écrit :
I'm a newbie and I'm having problems saving some data away to a new file. I've tried various things but the nearest I've got to doing this was the following:
tell application "TextEdit"
set newFile to "/Users/ericrobertson/Documents/New Notes.rtf"
activate
make new document with properties {path:newFile}
set text of document "New Notes.rtf" to "This is sample text"
save document "New Notes.rtf"
end tell
However although the document appears OK inTextEdit with the text included in it I get the message that I don't own the document "New Notes.rtf" and don't have permission to write to it. Do I have to set the file permissions in some way? I did try setting the name property as well as the path but this made no difference as it seemed to derive the name from just the path.
Incidentally i did find that if I just set the name property the path was set to /Users/ericrobertson/Library/Containers/com.apple.TextEdit/Data/Users/ericrobertson/Documents/New Notes.rtf.
I'm still on Lion (10.7.5) using TextEdit v1.7.1.
Eric Robertson
Hello
I forgot to write what is perhaps the most important feature.
The pathname which you got is the one of the file created by TextEdit in its sandbox work area.
If I understand well, only the application is allowed to write in this area.
It's why you got the message claiming "You don't have permissions…"
In the script which I posted, the file is created by System Events so you are allowed to edit it.
When you ask TextEdit to save in the prebuilt file, there is no problem because it's not in the application sandbox.
At this time, applications applying sandboxing aren't numerous so this kind of behavior is surprising but when the major applications will apply the rule, we will quickly accustomed to this new protocol.
Yvan KOENIG (VALLAURIS, France) vendredi 19 octobre 2012 23:59:26
Many thanks for this explanation. I had wondered why my approach hadn't worked.
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.apple.com/mailman/private/applescript-users/attachments/20121020/37b971a9/attachment.html>
------------------------------
Message: 2
Date: Sat, 20 Oct 2012 18:23:23 +0100
From: Eric Robertson <email@hidden>
To: email@hidden
Subject: Re: Problem saving a new file
Message-ID: <
email@hidden>
Content-Type: text/plain; charset="utf-8"
From: Miguel Torikachvili <email@hidden>
Subject: Re: Problem saving a new file
Date: 20 October 2012 04:37:21 GMT+01:00
To: email@hidden
You can use this to set manually the file`s path, name and content every time the script runs:
set pathToDocuments to (path to documents folder)
set pathToFolder to (choose folder default location (pathToDocuments))
set nameFile to text returned of (display dialog "Set new file name:" default answer "New Notes.rtf")
set newFile to (pathToDocuments & nameFile as string)
tell application "TextEdit"
activate
make new document with properties {path:newFile}
set text of document 1 to text returned of (display dialog "New file content:" default answer "Simple test")
save document 1 in newFile
quit
end tell
That's an interesting way of doing this - it let's me select a folder in Documents if I want to. However in the set newFile line shouldn't it be pathToFolder rather than pathToDocuments, to allow for the folder I've selected in Documents? If I make this change though the make new document line doesn't work while if I make a new folder in the choose folder action the set newFile line doesn't seem to work.
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.apple.com/mailman/private/applescript-users/attachments/20121020/bc1f42d6/attachment.html>
------------------------------
_______________________________________________
AppleScript-Users mailing list
email@hidden
https://lists.apple.com/mailman/listinfo/applescript-users
End of AppleScript-Users Digest, Vol 9, Issue 414
*************************************************