Search code examples
macosapplescriptfilenamesosx-yosemite

Applescript Choose file, filename


What I'm trying to make is something like this:

set filename to (choose file)
display dialog "The name of the chosen file is: " & filename

But when I use that script it will return a path to the file something like .../.../.../.../nameoffile.jar. But what I want is that it will return the filename and not the path (so just only nameoffile.jar). Is there a way to do that?

Thanks for reading, please give an answer as soon as possible ;),

Jort


Solution

  • Use the Finder Suite:

    set chosenfile to (choose file)
    
    tell application "Finder"
        display dialog "The name of the chosen file is: " & (name of chosenfile)
    end tell