Reading a filename as a variable

OK, this is probably a stupidly simple script, but for some reason i can’t get it to work. I want to read a filename, and turn it into a variable that i can use later on in the script. (Basically, I’m creating an html file where the title is based on the name of a jpg; creating the html is no problem, but trying to read the filename is proving harder than expected). I would have thought something simple like this would work:

set myvariable to name of (choose file)

i keep getting an error 'could not get name of alias"…

what am I missing??

It is not stupidly simple, just slightly weird. Only the Finder can get the name of a file using your syntax:

tell application "Finder" to set myvariable to name of (choose file)

But, that is clunky and no fun at all. Try the info for command instead:

set myvariable to name of (info for (choose file))

Good luck,

Hi,

use either the Finder

tell application "Finder" to set myvariable to name of (choose file)

or info for of the standard scripting addition

set myvariable to name of (info for (choose file))

Edit: Give me five, Craig :slight_smile:

No, Stefan, that is a 10!

Sweet. thanks guys, that did the trick!