• 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
Problems Writing to a File
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems Writing to a File


  • Subject: Problems Writing to a File
  • From: Steve Suranie <email@hidden>
  • Date: Thu, 10 Nov 2005 13:20:24 -0500
  • Thread-topic: Problems Writing to a File

I'm trying to write to a file but I am having some problems with my script:

If I use this script it works fine:

set theFilePath to "Macintosh
HD:Users:steve:Desktop:archiveTool:htmlFiles:tempFile.txt" as string
set theContent to "This is a test"

my writeFile(theFilePath, theContent)

--subs--

on writeFile(theFilePath, theContent)
    tell application "Finder"
        set f to (open for access theFilePath with write permission)
        write theContent to f
        close access f
    end tell
end writeFile

but I want to be able to use this script on any desktop. I can control the
folder hierarchy from "archiveTool" on down, it's the path to the desktop
which will be dynamic.

So I changed the script to this:

set theFilePath to (path to desktop) & "archiveTool:htmlFiles:tempFile.txt"
as string
set theContent to "This is a test"

my writeFile(theFilePath, theContent)

--subs--

on writeFile(theFilePath, theContent)
    tell application "Finder"
        set f to (open for access theFilePath with write permission)
        write theContent to f
        close access f
    end tell
end writeFile

I get an error message in the subroutine telling me the Finder cannot find
the file. I've tried open for access file theFilePath, open for access alias
theFilePath, wrapping it in a tell application "Finder" call and I still get
the same error.

When I return the path to desktop I get what I have been hard coding:

Macintosh HD:Users:steve:Desktop:

Can anyone explain what I am doing wrong?

Gracias

Steve

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problems Writing to a File
      • From: Michelle Steiner <email@hidden>
    • Re: Problems Writing to a File
      • From: Yvan KOENIG <email@hidden>
References: 
 >Re: Who has that property? (From: kai <email@hidden>)

  • Prev by Date: Re: Who has that property?
  • Next by Date: Re: Problems Writing to a File
  • Previous by thread: Re: Who has that property?
  • Next by thread: Re: Problems Writing to a File
  • Index(es):
    • Date
    • Thread