【发布时间】:2019-11-17 08:22:04
【问题描述】:
我一直在Excel上编写数据库,最近要支持Mac,Office 2016及以后的版本确实不支持内联代码,所以我不得不借用Mac。
我想制作一个“补丁”.app,当在最终用户计算机上运行时,它会将 AppleScripts 放入微软所说的文件中。
我能够检测文件夹是否存在并在需要时创建它们。我可以使用桌面和文档目录在命令上移动文件,但是如果我使用 onedrive 目录(文件从该目录执行)它不起作用。
我尝试了几种不同的代码结构,我是 Windows 用户,所以我正在学习操作系统。
我已经尝试过复制和不替换、复制、在 vs. using files、vs. file or items 和every 中输入目录。
这是我现在的代码,几乎可以获取正在运行的脚本的位置,然后删除应用程序的名称并添加其他脚本的正确目录。
检查文件夹是否存在,如果不存在则创建它们。
然后是指将源中的所有文件移动到目标。
set Source to POSIX path of ((path to me as text) & "::") & "AppleScripts/"
set ParentDestination to ("/Library/Application Scripts/")
set Destination to ("/Library/Application Scripts/com.microsoft.Excel/")
set ParentFound to false
set DestinationFound to false
tell application "System Events"
if exists folder ParentDestination then
set ParentFound to true
if exists folder Destination then
set DestinationFound to true
end if
end if
end tell
tell application "Finder"
if ParentFound = false then
make new folder at folder "Library" of startup disk with properties {name:"Application Scripts"}
end if
if DestinationFound = false then
make new folder at folder "Application Scripts" of folder "Library" of startup disk with properties {name:"com.microsoft.Excel"}
end if
duplicate (every item in Source) to Destination
end tell
我当前的错误是:Finder got an error: Handler can’t handle objects of this class.
这取决于我尝试的代码变体,但它始终在移动所有文件。
我知道这可能是一件简单的事情,但我什至还没有开始让 Excel 调用代码,所以我需要一些帮助。
【问题讨论】:
标签: excel vba macos applescript