Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Results 1 to 2 of 2
  1. #1
    sts24's Avatar
    sts24 is offline Registered User
    Join Date
    Sep 2002
    Location
    California
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting a file to read/write in Applescript

    I need to know what is wrong with this script:

    on will quit theObject
    set savepath to do shell script "whoami"
    set pathName to "Users:" & savepath & ":Library:Application Support:Note2Self:mainnote.n2s"
    set theData to contents of text view "text" of scroll view "text" of window "main" as string
    set theFile to open for access pathName with write permission
    write theData to theFile as string
    close access theFile
    return true
    end will quit

    I can get the thing to write a file, but the contents of the text view "text" doesn't write to the file. I was also wondering how to read this same file on launch. I can't get that to read. Is there an applescript command to overwrite a file so that on each quit, the file updates what is in the text view. Then on the next launch, it will open that same file in the text view "text".

    Any help, thanks.

  2. #2
    Vocal Velocity is offline Registered User
    Join Date
    Nov 2001
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write to file as handler

    here is a handler that does the trick for me.

    on write_to_file(this_data, target_file_path)
    try
    set the target_file_path to the target_file_path as text
    set the open_target_file to open for access the file target_file_path with write permission
    set eof of the open_target_file to 0 --> remove this line if you want written data appended to existing data
    write this_data to the open_target_file starting at eof
    close access the open_target_file
    return true
    on error
    try
    close access the open_target_file
    end try
    return false
    end try
    end write_to_file

 

 

Similar Threads

  1. Mac OS X and Win 2K Server
    By Go3iverson in forum Networking & Compatibility
    Replies: 4
    Last Post: June 11th, 2003, 02:37 PM
  2. I installed Fink under root and.....
    By Hydroglow in forum Unix & X11
    Replies: 5
    Last Post: November 27th, 2002, 03:57 PM
  3. How to compile stuff
    By fintler in forum Unix & X11
    Replies: 1
    Last Post: August 28th, 2002, 07:57 AM
  4. "Mac OS ROM" file issues
    By Clarifix in forum Mac Classic System & Software
    Replies: 1
    Last Post: July 20th, 2001, 08:52 AM
  5. vignette client on mac os x
    By erim in forum Software Programming & Web Scripting
    Replies: 8
    Last Post: July 13th, 2001, 01:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •