Open POSIX file file path

Hi all

Maybe I am to stupid to see it but why is this line working

tell application “Microsoft Excel” to open POSIX file “/Users/RDB/Desktop/ron.xlsx”

And this not

set filepath to “/Users/RDB/Desktop/ron.xlsx” as string

tell application “Microsoft Excel” to open POSIX file filepath

Thanks

Hi,

you’re not stupid, the reason is that AppleScript treats POSIX file differently if the argument is a literal string or a variable.

For more details please read : https://www.safaribooksonline.com/library/view/applescript-the-definitive/0596102119/ch13s09s02.html

Hi Stefan

Thanks for your reply

If I understand it correct, I make it this now and this is working.

set filepath to (POSIX path of file “/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx”)
tell application “Microsoft Excel” to open file filepath

Am I correct ?

Too complicated, Excel accepts simple POSIX paths

set filepath to "/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx"
tell application "Microsoft Excel" to open filepath

PS: please use the AppleScript tags when you’re posting code

Hi Stefan

I must use file in the script.

Reason is to avoid the grant access dialog in Office 2016

Then use alias which is also bridged to NSURL like file


set filepath to (POSIX file "/Users/rondebruin/Desktop/TestFolder2/zz1.xlsx") as alias
tell application "Microsoft Excel" to open filepath

Thanks for this Stefan, working correct, do you have a suggestion for saving a file in Excel and to avoid the grant access dialog. When you open a file you need File or Alias instead of only open to avoid that stupid dialog.

Really looking for some script that can fix this for saving a file also.

I don’t have Office 2016, please try

set filePath to "HD:path:to:file.xlsx"
set fileURL to filePath as «class furl»

this syntax creates explicit a file URL which is treated the same way as file and alias

No got the grant access dialog for the desktop with this tester

set destinationPath to (path to desktop as text) & "workbookName.xlsx"
set fileURL to destinationPath as «class furl»

tell application "Microsoft Excel"
	save active workbook in fileURL
end tell

I hope you have a other suggestion that I can try