Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Applescript Q: file specifications

9 views
Skip to first unread message

Jolly Roger

unread,
Mar 27, 2016, 12:53:19 PM3/27/16
to
On 2016-03-27, JF Mezei <jfmezei...@vaxination.ca> wrote:
>
> Question (trying to understand the file system).
>
> set outfile to open for access "/users/jfmezei/Pictures/iphoto_convert.txt" with write permission
>
> works
>
> set outfile to open for access "~/Pictures/iphoto_convert.txt" with write permission
>
> fails.
>
> is the interpretation of "~" something that only Bash understands and
> replaces it with your home directory spec ? I was under the impression
> that the "~" was something which was pervasive to the file system with
> lower level conversion to your home directory.

[cross posted to alt.comp.lang.applescript]

As others have said, shells typically do that for you; but not all tools
or interfaces do it automatically, including AppleScript. It is easy to
do it yourself in AppleScript though:

-- begin script
return my ResolveRelativePath("~/Pictures/iphoto_convert.txt")

on ResolveRelativePath(relativePath)
set homePath to POSIX path of (path to home folder)
return my SearchReplace(relativePath, "~/", homePath)
end ResolveRelativePath

on SearchReplace(sourceStr, searchString, replaceString)
-- replace <searchString> with <replaceString> in <sourceStr>
set searchStr to (searchString as text)
set replaceStr to (replaceString as text)
set sourceStr to (sourceStr as text)
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchString)
set theList to (every text item of sourceStr)
set AppleScript's text item delimiters to (replaceString)
set theString to theList as string
set AppleScript's text item delimiters to saveDelims
return theString
end SearchReplace
-- end script

--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.

JR
0 new messages