3

在 Excel 2016 中,以下 AppleScript:

tell application "Microsoft Excel"
    activate
    open "Macintosh HD:Users:path:to:file"
end tell

打开一个对话框,要求用户授予访问权限截屏 对于以前的 Excel 版本,文件会立即打开。微软似乎不再允许在没有明确用户许可的情况下从脚本打开文件。
有没有办法绕过对话框?

4

3 回答 3

5

使用文件对象或别名对象而不是字符串

tell application "Microsoft Excel"
    activate
    open file "Macintosh HD:Users:path:to:file"
    -- or --> open alias "Macintosh HD:Users:path:to:file"
end tell

当您有 POSIX 路径时,您可以使用它(open POSIX file "..."不起作用)

tell application "Microsoft Excel"
    activate
    set my_file to POSIX file "/Users/name/path/to/file"
    open my_file
end tell
于 2015-07-29T13:00:34.613 回答
0

这将打开选定的文件

tell application "Finder"
    open selection with MicrosoftExcel
end tell

MacOS 10.14 莫哈韦 | Excel for Mac 16.20

于 2019-01-15T13:19:13.223 回答
0

我使用这个 scriptlet 来解决访问权限对话框:

'with timeout of 10 seconds
    try
        -- File open may time out due to Apple's sandbox security rules. 
        open FileName
    on error        
        -- A Cancel and Grant Access dialog pops up and stops execution. Click the Grant Access button.
        tell application "System Events" to tell process "Microsoft Excel" to tell button "Grant Access" of window "Open" of application process "Microsoft Excel" of application "System Events" to perform action "AXPress"
    end try
end timeout'

Excel 版本:16.32,Mac OS 版本:10.14.6

于 2020-01-13T02:32:43.403 回答