• 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: Why do I get different results for this?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why do I get different results for this?


  • Subject: Re: Why do I get different results for this?
  • From: Axel Luttgens <email@hidden>
  • Date: Sat, 25 Apr 2009 11:26:26 +0200

Le 24 avr. 09 à 14:05, John C. Welch a écrit :

On 4/24/09 7:26 AM, "Shane Stanley" <email@hidden> wrote:

So in the first case, it's not actually resolving the furl, just looking for
it as a thing unto itself?

That's what it looks like to me.

So with some beating on it, we realized that unless you explicitly declare
even a string object as a string in the line you use it with POSIX file,
POSIX file, being astoundingly stupid, will be useless. My new mantra:


"POSIX file has no short-term memory"

Hello John,

Is 'POSIX file' really the culprit?

The Finder seems to try to do something with 'POSIX file' on its own, instead of delegating it:

    set P to "/Users"
    tell application "Finder"
        POSIX file P
        --> Error in Finder: can't get POSIX file "/Users"
    end tell

This may be observed with other applications as well; just replace "Finder" by "Mail" or "Terminal" or...
Anyway, the fact is then hidden by the 'exists' command:


    set P to "/Users"
    tell application "Finder"
        exists POSIX file P
        --> false
    end tell

So, the "right" way seems to be:

    set P to "/Users"
    tell application "Finder"
        tell me to POSIX file P
        --> file "StartupDisk:Users"
        exists result
        --> true
    end tell

which of course may be shortened, for example as:

    set P to "/Users"
    tell application "Finder"
        exists (my POSIX file P)
        --> true
    end tell

Now, the other funny part. Jon has suggested to make use of an 'as string' coercion; and indeed, one has:

    set P to "/Users"
    tell application "Finder"
        exists POSIX file P as string
	--> true
    end tell

But the explanation is twofold.
First, with the coercion, the Finder suddenly appears to correctly handle 'POSIX path':


    set P to "/Users"
    tell application "Finder"
        POSIX file P as string
	--> "StartupDisk:Users:"
    end tell

Second, when applied to a string, Finder's command 'exists' seems to infer that it should test for the existence of a disk item with the provided textual path:

    set P to "/Users"
    tell application "Finder"
        exists "StartupDisk:Users:"
        --> true
    end tell

A kind of string to file coercion, thus. One could wonder about such a design choice; for example, it could have been decided that a string should be taken as the name of a window to be tested, or that a string always exists...
Let's thus chose a coercion more suitable at showing the programmer's intent:


    set P to "/Users"
    tell application "Finder"
        exists POSIX file P as file
	--> true
    end tell

Hmm... as an afterthought, both coercions look rather nonsensical, don't they?
Axel


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Why do I get different results for this? (From: "John C. Welch" <email@hidden>)

  • Prev by Date: Mail's document
  • Next by Date: Re: Safari and "make window"
  • Previous by thread: Re: Why do I get different results for this?
  • Next by thread: Correction: ".app" version works, ".scpt" version doesn't
  • Index(es):
    • Date
    • Thread