Edit: Found it!
set theFile to (choose file)
set fileName to name of (info for theFile)
display dialog fileName
Is there a way to keep the current app in front when calling another app with a tell block?
Alternatively, is there a simple way to find the name of a file in standard applescript (ie. without calling the finder)?
don’t activate the other app
System Events
or
name of (info for alias) from Standard Additions
Thanks Stephan! I think you helped me find it. This will be useful the future.
I didn’t tell the finder to activate but it did anyway. I think I found the reason why. choosing a file brings up the finder’s gui which activates it the finder. This code activates the finder:
tell application "Finder"
set theFile to (choose file) --this line activates the finder GUI
set fileName to name of theFile
end tell
display dialog fileName
this code keeps the finder deactivated:
set theFile to (choose file) --this line isn't in the finder tell block thus doesn't activate it
tell application "Finder"
set fileName to name of theFile
end tell
display dialog fileName
BTW, system events has the same behavior.