converting Win-like path to alias

I have a path to file that looks like this …

  "/Users/username/myfolder/myfile.pdf"

How easily (in one line if possible) to convert it to an alias?

Hi,

first of all: this is no Win-like path, windows uses backslashes.
A path separated by slashes is a usual UNIX (POSIX) path


set POSIXpath to "/Users/username/myfolder/myfile.pdf"
set theAlias to POSIX file POSIXpath as alias

Note: the one-liner syntax


set theAlias to POSIX file "/Users/username/myfolder/myfile.pdf" as alias

could cause problems, so it’s recommended to assign first the literal string to a variable

I tried in such way but script editor throws an error:

Can’t make {POSIX file, “myPath”} into type alias

Perhaps there are %20 etc in file path or Any idea?

You’re definitely using a different syntax.
The error says, you’re going to coerce a list to an alias

a full script is

set foo to (open for access (POSIX file "/Own/$$$wf.ini")) --file as object
set iniF to (read foo as text)--just a string in format ""/../../..
close access foo

set a_file to POSIX file & iniF as alias-- as you said

there is No any list at all

believe me, there is one, error messages don’t lie !! :wink:

set a_file to POSIX file & iniF as alias-- as you said

POSIX file expects a string argument, POSIX file & iniF is a list out of 2 different classes, actually it’s nothing.
You probably mean

set a_file to POSIX file iniF as alias

Can you explain me where I’m wrong:

set f to (open for access (POSIX file "/Own/$$$wf.ini")) --file as object
set iniFileContent to (read f as text)--contents is literally: /Own/MTS_blackberry_phone_OUT/DCS%20Preview/mts_blackberry_phone.pdf
close access f

set attachFilePath to POSIX file iniFileContent as alias -- here is error -->can't make file into type alias

if I read the file its contents comes as string which converted into Macintosh file path, however there is a bug

The bug is, an escaped URL space character (%20) is no valid part of a POSIX or HFS path.
You have to replace it with a real space character


set iniFileContent to read file ((path to startup disk as text) & "Own:$$$wf.ini")

set {TID, text item delimiters} to {text item delimiters, "%20"}
set iniFileContent to text items of iniFileContent
set text item delimiters to space
set iniFileContent to iniFileContent as text
set text item delimiters to TID

set attachFilePath to POSIX file iniFileContent as alias

Note: To read the contents of a text file, the form open for access is not necessary

Thanx a lot.
It works!

By the way is any way to run script step-by-step (create breakpoints etc) in Script Editor?

No, it isn’t. Only the commercial application Script Debugger provides these functions