Re: Another script to analyize, please
Re: Another script to analyize, please
- Subject: Re: Another script to analyize, please
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 04 Dec 2003 17:21:56 -0800
On 12/4/03 7:53 AM, "Michelle Steiner" <email@hidden> wrote:
>
set docpath to choose file name
>
set thedoc to open for access docpath with write permission
>
close access thedoc
>
tell application "Finder"
>
set file type of file docpath to "GIFf"
>
set the file creator of file docpath to "GKON"
>
>
end tell
>
>
If I leave out "file" in setting the file type or file creator, I get a
>
stack overflow, but with the word file there, the log shows
>
>
set file type of file (file "Dora:Users:michelle:Desktop:untitled") to
>
"GIFf"
>
"GIFf"
>
set file creator of file (file "Dora:Users:michelle:Desktop:untitled")
>
to "GKON"
>
>
It seems to me that "file" is redundant.
You haven't checked the dictionary for 'choose file name':
choose file name: Get a new file reference from the user, without creating
the file (defined in: StandardAdditions.osax)
choose file name
[with prompt string] -- the text to display in the file creation
dialog box
[default name string] -- the default name for the new file
[default location alias] -- the default file location
Result: file -- the file the user specified
The result is not 'string' or 'Unicode text': it's file. Your variable name
'docpath' and putting the Finder's own 'file' in front seem to indicate that
you think the result "should be" text. But it isn't - you could coerce to to
text, but why bother? Just give the variable an appropriate name so you
don't get confused, then don't stick 'file' in front of it. It doesn't work
without the Finder's 'file' or 'alias' because you can't set the file type
or creator type of the sort of 'file' (actually a file specification of some
sort) - only of a real file or alias. So make set a variable as alias to the
real file made by 'open for access'. Again, it looks to me as if you may
think that setting a variable 'thedoc' makes the 'open for access' command
itself return a real file : no it doesn't, it returns a file reference - an
integer. (Log it and you'll see for yourself.) You have to set a variable to
the file spec (or file path) 'as alias', or else a path 'as Unicode text'
and then use the Finder's 'file'. But Chris Nebel has told me that the
Finder can occasionally have trouble with its 'file' before file paths - it
was really designed for the 'file A of folder B of disk C' sort of
construction, while it will always handle 'alias filePath' OK, so that's
what I use now.
Finally, you didn't check the Finer dictionary either. file creator' is the
term used by the 'info for' scripting addition, not the Finder. And it's
r/o. The Finder uses 'creator type', and you can set that.
This works. I've used 3 different variable names to make clear what each
does, but you could use just one variable, constantly reset, if you prefer.
set fileSpec to choose file name
set fileRefNum to open for access fileSpec with write permission
close access fileRefNum
set theFile to fileSpec as alias
tell application "Finder"
set file type of theFile to "GIFf"
set creator type of theFile to "GKON"
end tell
>
>
Further, although file type works, when the script reaches the file
>
creator line, it throws this error:
>
>
"Finder got an error: Can't set file creator of file (file
>
\"Dora:Users:michelle:Desktop:untitled\") to \"GKON\"."
>
>
Oh, I was trying to change file type and creator as an experiment; I
>
realize that I can't convert a text document to a GIF quite so easily.
set the creator type
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.