• 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: problem with POSIX path of Š
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with POSIX path of Š


  • Subject: Re: problem with POSIX path of Š
  • From: Jim Underwood <email@hidden>
  • Date: Wed, 14 Sep 2016 05:05:25 +0000
  • Thread-topic: problem with POSIX path of Š

Here is an improved version of my getPOSIXPath handler.

It ensures that, in the case of a folder path, the path does NOT end in a "/", consistent with Unix conventions.





use AppleScript version "2.4" -- Yosemite (10.10) or later

use scripting additions


set tempFolderHFS to path to home folder as text

set tempFileHFS to tempFolderHFS & "test.txt"

set homeAlias to path to home folder

set fileURL to tempFileHFS as «class furl»

set myList to {"one", "two", "three"}


tell application "TextEdit" -- as an example of tell block

  

  set pathFolderFromHFS to my getPOSIXPath(tempFolderHFS)

  set pathFileFromHFS to my getPOSIXPath(tempFileHFS)

  set pathFromAlias to my getPOSIXPath(homeAlias)

  set pathFromTilde to my getPOSIXPath("~")

  set pathFromTildeFolder to my getPOSIXPath("~/Test")

  set pathFromPOSIX to my getPOSIXPath("/Users/Shared/")

  set pathfromFURL to my getPOSIXPath(fileURL)

  --set errorTest to my getPOSIXPath(myList)

  

end tell



--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

on getPOSIXPath(pAnyPath)

  --–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

  --  VER: 1.1    2016-09-13

  (*

    PURPOSE:     Convert any path or alias to POSIX path

    PARAMETERS:

      • pAnyPath: Any Path; class: text, alias, or furl

    RETURNS:     POSIX Path (Never has "/" at end)

    AUTHOR.@JMichaelTX

    REF:         makeAlias() by @ccstone (Chris Stone)

  --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  *)

  

  --- FROM ALIAS ---

  if class of pAnyPath is alias then

    set posixPathStr to POSIX path of pAnyPath as text

    

    --- FROM TEXT ---

  else if class of pAnyPath is text then

    if pAnyPath contains ":" then -- HFS

      set posixPathStr to POSIX path of pAnyPath

      

      --- FROM POSIX Path (various forms/shortcuts) ---

    else if pAnyPath is "~" or pAnyPath is "~/" then

      set posixPathStr to POSIX path of (path to home folder) as text

    else if pAnyPath starts with "~/" then

      set posixPathStr to (POSIX path of (path to home folder)) & text 3 thru -1 of pAnyPath

    else if pAnyPath starts with "/" then

      set posixPathStr to pAnyPath

    end if

    

    

    --- FROM FILE URL ---

  else if class of pAnyPath is «class furl» then

    set posixPathStr to POSIX path of (pAnyPath as text)

    

  else --- INVALID CLASS ---

    

    set classPath to class of pAnyPath

    error "\"" & classPath & ¬

      "\" is NOT a valid class for:" & return & ¬

      "Handler:  on getPOSIXPath (pAnyPath)" & return & return & "Must be: text, alias, or furl"

  end if

  

  --- MAKE SURE PATH DOES NOT END WITH "/" ---

  if (last character of posixPathStr = "/") then

    set posixPathStr to text 1 thru -2 of posixPathStr

  end if

  

  

  return posixPathStr

  

end getPOSIXPath





Best Regards,

 

Jim Underwood

aka JMichaelTX


 _______________________________________________
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: 
 >problem with POSIX path of … (From: Yvan KOENIG <email@hidden>)
 >Re: problem with POSIX path of … (From: Axel Luttgens <email@hidden>)
 >Re: problem with POSIX path of … (From: Yvan KOENIG <email@hidden>)
 >Re: problem with POSIX path of … (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Need to remove Dock icon
  • Next by Date: Re: Need to remove Dock icon
  • Previous by thread: Re: problem with POSIX path of …
  • Next by thread: Fwd: problem with POSIX path of …
  • Index(es):
    • Date
    • Thread