Re: Files, Folders and Paths
Re: Files, Folders and Paths
- Subject: Re: Files, Folders and Paths
- From: Christopher Stone via AppleScript-Users <email@hidden>
- Date: Wed, 10 May 2023 21:13:47 -0500
> On May 09, 2023, at 12:37, Gil Dawson via AppleScript-Users
> <email@hidden> wrote:
>
> I've been reviewing Apple's documentation
> <https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ReferenceFilesandFolders.html>
> on files, folders, paths and such. Several examples surprised me...
>
> on convertPathToAlias(thePath)
> tell application "System Events"
> try
> return (path of disk item (thePath as string)) as alias
> on error
> return (path of disk item (path of thePath) as string)
> as alias
> end try
> end tell
> end convertPathToAlias
Hey Gil,
That handler is actually impressively powerful and deceptively simple.
It will happily convert any normal file/folder object or path string you throw
at it...
-Chris
--------------------------------------------------------
set tildePath to "~/test_directory/test"
set alias1 to convertPathToAlias(tildePath)
set hfsPath to alias1 as text
set alias2 to convertPathToAlias(tildePath)
set theFURL to alias1 as «class furl»
set alias3 to convertPathToAlias(theFURL)
tell application "System Events" to set sevFileRef to disk item
"~/test_directory/test"
set alias4 to convertPathToAlias(sevFileRef)
tell application "Finder" to set finderFileRef to file alias1
set alias5 to convertPathToAlias(finderFileRef)
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on convertPathToAlias(thePath)
tell application "System Events"
try
return (path of disk item (thePath as text)) as alias
on error
return (path of disk item (path of thePath) as text) as
alias
end try
end tell
end convertPathToAlias
--------------------------------------------------------
_______________________________________________
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