• 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: Does a NSURL Have a Valid Target
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does a NSURL Have a Valid Target


  • Subject: Re: Does a NSURL Have a Valid Target
  • From: Jim Underwood <email@hidden>
  • Date: Thu, 02 Mar 2017 19:45:08 +0000
  • Thread-topic: Does a NSURL Have a Valid Target

Repost script to correct spelling error of "tilde".



-------------------------------------------------------------------------------------------

# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }

# Mod:  @JMichaelTX (refactor)  2017-03-02

# dCre: 2017/03/02 11:31

# dMod: 2017/03/02 11:33

# Appl: AppleScriptObjC

# Task: Determine whether a NSURL has a valid target.

# Libs: None

# Osax: None

# Tags: @Applescript, @Script, @ASObjC, @Test, @NSURL, @Valid, @Target

-------------------------------------------------------------------------------------------

use AppleScript version "2.4" -- Yosemite (10.10) or later -- I'm not sure about os versions...

use framework "Foundation"

use scripting additions

-------------------------------------------------------------------------------------------


set folderPathExisting to POSIX path of (path to downloads folder)

set folderPathNotExisting to POSIX path of (path to downloads folder) & "Nuts!"


## @JMichaelTX:  My Test Cases


set goodPathBool to my doesItemExist(folderPathExisting)

set badPathBool to my doesItemExist(folderPathNotExisting)

set invalidPathBool to my doesItemExist("not a valid path")

set pathWithTildeBool to my doesItemExist("~/Downloads")


log ("goodPathBool: " & goodPathBool as text)

log ("badPathBool: " & badPathBool as text)

log ("invalidPathBool: " & invalidPathBool as text)

log ("pathWithTildeBool: " & pathWithTildeBool as text)

-------------------------------------------------------------------------------------------


--

## Refactor into Handler by @JMichaelTX


on doesItemExist(pPOSIXPath)

  local myNSURL, doesItExistBool

  

  ## @JMichaelTX:  Add support for tilde (~) Path

  

  set pPOSIXPath to (current application's NSString's stringWithString:pPOSIXPath)'s stringByExpandingTildeInPath

  

  set myNSURL to current application's |NSURL|'s fileURLWithPath:pPOSIXPath

  set doesItExistBool to (myNSURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean

  

  return doesItExistBool

end doesItemExist



RESULTS:


(*goodPathBool: true*)
(*badPathBool: false*)
(*invalidPathBool: false*)
(*pathWithTildeBool: true*)




Best Regards,

Jim Underwood
aka JMichaelTX


From: <applescript-users-bounces+jmichael=email@hidden> on behalf of JMichael <email@hidden>
Date: Thu, Mar 2, 2017 at 1:32 PM
To: "ASUL (AppleScript)" <email@hidden>
Subject: Re: Does a NSURL Have a Valid Target

Chris and Shane, thanks for sharing this great little script.

I have made a small mod to refactor into a handler, and add support for a tilde path:

doesItemExist(pPOSIXPath)

 _______________________________________________
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: 
 >Does a NSURL Have a Valid Target (From: Christopher Stone <email@hidden>)
 >Re: Does a NSURL Have a Valid Target (From: Jim Underwood <email@hidden>)

  • Prev by Date: Re: Does a NSURL Have a Valid Target
  • Next by Date: Re: Stupid Finder, or is it me?
  • Previous by thread: Re: Does a NSURL Have a Valid Target
  • Next by thread: Conversion of ISO Date String to AppleScript Date
  • Index(es):
    • Date
    • Thread