POSIX to alias conversion

TRying to convert a POSIX file path to an alias with the following statement:

set myFilePathAlias to (POSIX file myFilePath as alias)

myFilePath is obtained from the filepath property of a file alarm in iCal and a display dialog shows it as:

file://localhost/Users/Dad/Documents/Scripts/Compiled%20Scripts/RepeatTask.app

The Applescript stops with an error on the set myFilePathAlias statement “Cannot make POSIX file into type alias”, listing the above POSIX file path.

What am I doing wrong?

Thanks,
Pete

Hi,

the problem is, you’re trying to coerce a file URL to an alias, not a POSIX path
try this, the perl line coerces file URL to POSIX path


set fileURL to "file://localhost/Users/Dad/Documents/Scripts/Compiled%20Scripts/RepeatTask.app"
set myFilePath to (do shell script "perl -e 'use URI::file; print URI->new(\"" & fileURL & "\")->file;'")
set myFilePathAlias to (POSIX file myFilePath as alias)

Thanks Stefan.

The Applescript dictionary for iCal states that the filepath is “the (POSIX) file path to be opened by the alarm” but sounds like that’s incorrect unless I need to change the way set myFilePath. Right now, it’s:

set myFilePath to filepath of item j of myAlarms (I’m in a repeat loop with MyAlarms set to open file alarms)

I can certainly use the perl code you gave me but is there a way to set myFilePath so that it ends up with a POSIX file path?

Thanks,
Pete

the dictionary is obviously lying.
The filepath property of open file alarm returns a file URL, so you have to coerce it.
Just cutting file://localhost is not sufficient, the escaped (e.g. %20) characters have also to be considered.