• 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
Path relative to current script? Re: POSIX file question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Path relative to current script? Re: POSIX file question


  • Subject: Path relative to current script? Re: POSIX file question
  • From: Don Briggs <email@hidden>
  • Date: Thu, 23 Oct 2003 20:17:18 -0700

Donald Liu was bold enough to ask a question related to mine:

I'd like to use AppleScript to test an application in development.
I'll do it by asking MyApp to open a test document. (Call it "foo.bar" )
(Some fine day, after I get the app running to zeroeth order, we can
call this "regression testing.")

I want the test script and its test document to be in the same folder.
I'd like to be able to move the folder and still perform the test.

I think I need to build a path relative to the path of the test script.

I'd like to:
 launch the test script in Script Editor
 determine the path to the script I've just launched
 perform a simple operation to change it to the path of my test
document
 tell my test app to open its test document.

The first step might look like this:

property pathToThisScript : ""

tell application "Script Editor"
set pathToThisScript to path of front document
end tell

But what next?

Thanks,
Don (a different Donald, not Mr. Liu)

On Oct 23, 2003, at 6:29 PM, Christopher Nebel wrote:

> On Oct 22, 2003, at 4:07 PM, Donald Liu wrote:
>
>> I have a bad feeling that this has been discussed before, but I'm
>> currently blanking out and can't figure out what I'm doing wrong. I
>> searched and found few on the Apple/AppleScript web-site, they didn't
>> provide the solution I'm looking for. If anyone can help me, I'd
>> really appreciate it.
>>
>> If I have the following POSIX path,
>>
>> set foo to "~/Documents/QuickLooks/"
>>
>> and want to convert it to the AppleScript file object, I do this...
>>
>> set goo to POSIX file foo
>>
>> but this returns ":~:Documents:QuickLooks:". How do I make it so that
>> it returns "Macintosh HD:Users:dliu:Documents:QuickLooks:"
>
> The "POSIX file" class doesn't handle ~ specially, like the shell
> does. (There is an enhancement request filed on this.) To get the
> effect you're looking for, you have to ask someone where the home
> directory is and tack that on somehow. Here are a two ways:
>
> set foo to (do shell script "echo ~") & "/Documents/QuickLooks/"
> set goo to POSIX file foo
>
> set foo to (system attribute "HOME") & "/Documents/QuickLooks/"
> set goo to POSIX file foo
>
> Alternatively, you could approach the problem sideways:
>
> tell application "Finder"
> get folder "QuickLooks" of folder "Documents" of home as alias
> get folder "Documents:QuickLooks" of home as alias
> -- or, let the system find the Documents folder for you...
> get folder "QuickLooks" of (path to documents folder) as alias
> end tell
>
> (Depending on the eventual destination, you may or may not need the
> "as alias".)
>
>
> --Chris Nebel
> AppleScript Engineering
> _______________________________________________
> 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.
_______________________________________________
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: Path relative to current script? Re: POSIX file question
      • From: Michelle Steiner <email@hidden>
References: 
 >POSIX file question (From: Donald Liu <email@hidden>)
 >Re: POSIX file question (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Simple question - how2 launch apps in OS X via a script
  • Next by Date: Mail.app word wrap 72 characters
  • Previous by thread: Re: POSIX file question
  • Next by thread: Re: Path relative to current script? Re: POSIX file question
  • Index(es):
    • Date
    • Thread