Re: Creating new file etc
Re: Creating new file etc
- Subject: Re: Creating new file etc
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 13 Apr 2007 11:02:56 -0700
- Thread-topic: Creating new file etc
Title: Re: Creating new file etc
On 4/12/07 10:24 p.m, "email@hidden" wrote:
> Gregory White <email@hidden>
> Subject: Creating new file etc
> To: apple script <email@hidden>
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Dear List, I would be very grateful for any help you could give me as
> I've been struggling with it for a few days.
Greg, you're off to a good start here.
I noticed a couple minor problems with your script that were easily taken care of.
First, you weren't getting a legitimate path to your bookmaker folder.
I've always found it's a good practice to cooerce paths to aliases. If that fails, then applescript won't see the file or folder.
> my write_to_file(this_Book, this_file, false)
> on write_to_file(this_data, target_file, append_data)
Here, your script sends "this_file" as an optional parameter to your handler, but the handler declaration uses "target_file" as a variable,
So this line:
> set the target_file to the this_file as text
Falis because this_file is not declared inside the handler.
It's a good habit to use different names for your variables inside handlers than outside to avoid this kind of confusion.
Here is your script with a couple tweaks.
HTH,
ES
--------------
tell application "Finder"
copy (the clipboard) to Clip_Board
set homeFolder to path to home folder as unicode text
set Bookmaker_Folder to homeFolder & "Documents:ReferenceWorks Bookmaker" as alias
end tell
set this_Book to "Once upon a time in Silicon Valley... Hello"
set this_file to (((Bookmaker_Folder) as text) & "New Book")
my write_to_file(this_Book, this_file, false)
on write_to_file(this_data, this_file, append_data)
try
set the target_file to the this_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error errMsg number errNum
display dialog errMsg & return & errNum
try
close access file target_file
end try
return false
end try
end write_to_file
----
>
> set Bookmaker_Folder to "home:Documents:ReferenceWorks Bookmaker:"
> --in the finished script I would set this_book to Clip_Board
>
>
> set this_Book to "Once upon a time in Silicon Valley... Hello"
> set this_file to (((Bookmaker_Folder) as text) & "New Book")
> my write_to_file(this_Book, this_file, false)
> on write_to_file(this_data, target_file, append_data)
> try
> set the target_file to the this_file as text
> set the open_target_file to ¬
> open for access file target_file with write permission
> if append_data is false then ¬
> set eof of the open_target_file to 0
> write this_data to the open_target_file starting at eof
> close access the open_target_file
> return true
> on error
> try
> close access file target_file
> end try
> return false
> end try
> end write_to_file
_______________________________________________
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