Re: get alias from ~/path
Re: get alias from ~/path
- Subject: Re: get alias from ~/path
- From: Donald Hall <email@hidden>
- Date: Sat, 1 Mar 2003 23:30:08 -0700
Andrew,
Thanks very much. I should have remembered to look in the AS dictionary.
Here is what I ended up with:
set fileName to "~/CustomInfo.plist" -- just a file for testing
getAlias from fileName
to getAlias from pathName
if pathName starts with "~" then
set userPath to POSIX path of (path to current user
folder as text)
set pathName to userPath & "/" & (characters 2 thru
-1 of pathName)
end if
set theAlias to alias POSIX file pathName
return theAlias
end getAlias
Thanks also to John Delacour for his suggestions. I decided to stay
with 'characters' rather than 'text'. I was afraid that 'text' would
depend on how the text item delimiters are set, but apparently not.
Why would it be better?
Don
>
The best and safest option is to use the much-overlooked 'path to' command:
>
>
path to users folder
>
-->alias "Macintosh HD:Users:"
>
>
Or
>
>
path to current user folder
>
-->alias "Macintosh HD:Users:username"
>
>
This code is totally portable, and will work on any internationalized
>
system, including those where "Users" is not the name of the user folder.
>
>
The 'path to' command provides safe methods for locating many of the system
>
and user specific folders on a system.
>
>
Andrew
>
:)
>
>
On 2/28/03 10:53 PM, "Donald Hall" <email@hidden> wrote:
>
>
> I have a situation where I want to be able to get an AppleScript
>
> alias for a file from its POSIX path when the path is in the
>
> shortened form "~/pathto/file". I need to be able to expand the tilde
>
> into "/Users/username". Here is what I came up with:
>
>
>
> set fileName to "~/CustomInfo.plist" -- just a file to do the test with
>
> getAlias from fileName
>
>
>
> to getAlias from pathName
>
> if pathName starts with "~" then
>
> set userName to do shell script "id -un"
>
> set pathName to "/Users/" & userName & ,
>
> "/" & (characters 2 thru -1 of pathName) as text
>
> end if
>
> set theAlias to alias POSIX file pathName
>
> return theAlias
>
> end getAlias
>
>
>
> This seems to work on my machine. Is 'id' the right command to use?
>
> There is also 'logname'.
>
>
>
> Thanks,
>
>
>
> Don
>
> --
>
> Donald S. Hall, Ph.D.
>
> Apps & More Software Design, Inc.
>
> email@hidden
>
> http://www.appsandmore.com
>
> _______________________________________________
>
> applescript-users mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/applescript-users
>
> Do not post admin requests to the list. They will be ignored.
--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://www.appsandmore.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.