• 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: [NEWBIE] Open file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NEWBIE] Open file


  • Subject: Re: [NEWBIE] Open file
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 05 Nov 2002 09:40:15 -0800

On 11/5/02 9:09 AM, "Stiphane Pinel" <email@hidden> wrote:

> How can I open a file "myfile.txt" which is in the same folder as the script

It depends mostly on whether "the script" is a script APPLICATION or a
compiled script being run by another app. I'll assume it's an application
(applet or droplet). That allows you to find the script as 'path to me'. You
can do the rest in the Finder, or you can do it without reference to the
Finder:

set myPath to (path to me as string) -- use (path to me) as Unicode text
in AS 1.8.3 and later for non-European filepaths included

set AppleScript's text item delimiters to {":"}
set myFolderPath to (text items 1 thru -2 of myPath) as string & ":"
-- again 'as Unicode text' if AS 1.8.3 or later

set AppleScript's text item delimiters to {""}

try
set textFilePath to (myFolderPath & "myfile.txt")
tell application "Finder" to open file textFilePath
on error
beep
display dialog "You have no such \"myfile.txt\" file in the same
folder as this script." buttons {"OK"} default button 1 with icon 0
end try



To do it in the Finder:


set myPath to (path to me as string) -- use (path to me) as Unicode text
in AS 1.8.3 and later for non-European filepaths included

tell application "Finder"
set myFolder to container of file myPath
try
open file "myfile.txt" of myFolder
on error
beep
display dialog "You have no such \"myfile.txt\" file in the same
folder as this script." buttons {"OK"} default button 1 with icon 0
end try
end tell


--
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.

  • Follow-Ups:
    • Re: [NEWBIE] Open file
      • From: Stéphane Pinel <email@hidden>
References: 
 >[NEWBIE] Open file (From: Stéphane Pinel <email@hidden>)

  • Prev by Date: Re: [NEWBIE] Open file
  • Next by Date: Re: Change Color of a ColorWell object in Project Builder
  • Previous by thread: Re: [NEWBIE] Open file
  • Next by thread: Re: [NEWBIE] Open file
  • Index(es):
    • Date
    • Thread