AHolasek
AHolasek

Reputation: 211

In applescript 'choose file', only allow folders to be selected, and how to get text returned

How would you only allow the user to select folders when using the 'choose from file' prompt? Also, once they select the file, how would you get the text returned for the path to the file. (So the text returned would be /Users/myname/Desktop/afile)
My current unworking code is as follows:
set d to the text returned of (choose file with prompt "Please choose a file:" of type {"??", "??"} default location "/Users/myname/Desktop")
When running this in applescript, it only lets you choose files, and once you do so, I get the error
error "Can’t get text returned of alias \"Macintosh HD:Users:myname:Desktop:filename.extention:\"." number -1728 from text returned of alias "Macintosh HD:Users:myname:Desktop:filename.extention:"

Upvotes: 0

Views: 733

Answers (1)

vadian
vadian

Reputation: 285072

choose file returns an alias specifier to the chosen file. You mixed it up with display dialog which returns a record containing text returned.

To get the slash separated POSIX path put POSIX path in front of the expression

set d to POSIX path of (choose file with prompt "Please choose a file:" default location (path to desktop))

If you want to select folders use choose folder, same syntax

set d to POSIX path of (choose folder with prompt "Please choose a folder:" default location (path to desktop))

Upvotes: 2

Related Questions