Re: Files, Folders and Paths
Re: Files, Folders and Paths
- Subject: Re: Files, Folders and Paths
- From: Gil Dawson via AppleScript-Users <email@hidden>
- Date: Wed, 10 May 2023 01:03:07 -0700
Ah! I see.
Thank you, both John and Joel, for very clear explanations.
--Gil
> On May 9, 2023, at 8:16 PM, John Garrigues <email@hidden
> <mailto:email@hidden>> wrote:
>
> The first `try` block in the `convertPathToAlias` handler attempts to convert
> the input `thePath` directly to an alias using the `path` property of a `disk
> item` object in System Events. If `thePath` is already in the correct format
> for the `path` property to work, then the first `try` block will succeed and
> return an alias.
>
> However, if `thePath` is not in the correct format, the first `try` block
> will fail and an error will be thrown. In that case, the handler falls back
> to the second `try` block, which uses the `path` property of a `disk item`
> object to convert the `path` property of `thePath` to a string, and then
> converts that string to an alias. This fallback can succeed if the issue with
> `thePath` is only related to its format or type, rather than the existence of
> the file or folder it refers to.
>
> Therefore, the first `try` block might fail if `thePath` is not in a format
> that can be directly used by the `path` property, but the second `try` block
> might succeed if it can convert `thePath` to a string that can be used by the
> `path` property.
>
>
>
>> On May 9, 2023, at 10:37, Gil Dawson via AppleScript-Users
>> <email@hidden
>> <mailto:email@hidden>> wrote:
>>
>> Converting a Path to an Alias
>> The handler in Listing 15-19 converts strings, path objects, POSIX file
>> objects, Finder paths, and System Events paths to alias format.
>>
>> Listing 15-19AppleScript: Handler that converts a path to an AppleScript
>> alias
>>
>> 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
>>
>> Under what conditions would the first try fail, but the second one succeed?
>
_______________________________________________
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