• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using a variable in a property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using a variable in a property


  • Subject: Re: Using a variable in a property
  • From: Michelle Steiner <email@hidden>
  • Date: Tue, 11 Dec 2001 21:28:14 -0700

On 12/11/01 6:00 PM, William Barnes <email@hidden> wrote:

>The script chokes on the "make file..." line with an error message
>"Invalid key form". I am assuming that this results from my trying to use
>the variable 'filnam' for the 'name' property, and it cannot be coerced
>into a string. Any suggestions would be greatly appreciated.

There are a few problems with the script. Here's one that works. I'll
try to explain the changes I made.

--Michelle

(*
I created some dummy variables rather than take the text from a message;
this shouldn't change anything
*)

set subjectvar to "abcdefghijklmnopqrstuvwxyz123456789"
set filnam to text 26 thru 35 of subjectvar

(*
"text 26 through 35" saves you from having to declare it as text later;
it saves some memory and makes it a bit faster--and reads cleaner IMO
*)

set destfol to "dora:foo:"
set bodyvar to "this is dummy text"

(*
only the following line needs to be inside the tell-Finder wrapper.
*)

tell application "Finder"
--activate not really needed

set the newfile to (make new file at folder destfol with properties
{name:filnam, creator type:"NISI", file type:"TEXT"})

(* "new" is supposed to be required, but is actually optional; I think
it's cleaner with it though.
The important thing is that you need to specify "folder" before destfol;
otherwise the script thinks you're trying to make a new file at a string.
*)

end tell

(*
The rest does not need, and should not be, inside the Tell-finder wrapper
*)

set filRef to (open for access (newfile as alias) with write permission)

(*
"newfile as alias" is necessary because otherwise newfile is "file
z123456789 of folder foo of volume dora" and open for access does not
understand that syntax.

Also, set a filRef to the file, so it can be referenced by the file
reference instead of the full filepath.
*)

write bodyvar to filRef

--save is not needed; it would generate an error

close access filRef

----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------


  • Prev by Date: PPP
  • Next by Date: Waiting for Godot
  • Previous by thread: Re: Using a variable in a property
  • Next by thread: Coerce string to record or something like that?
  • Index(es):
    • Date
    • Thread