applescript - Applescript 创建具有属性的文件夹
问题描述
这是我的代码:
on startButton_(sender)
set folderDestination to choose folder
log folderDestination
log nameOfFolder
tell application "Finder"
make new folder at folderDestination with properties {name:nameOfFolder}
end tell
end startButton_
想法是在文件夹目标 (folderDestination) 处创建一个文件夹,其名称为文件夹名称 (nameOfFolder)。这是来自控制台的错误
2021-03-13 09:28:02.844240+0100 Folder Creator[1571:39314] *** -[AppDelegate startButton:]: Finder got an error: Can’t make «class ocid» id «data optr0000000059FEE7F626C77C59» into type Unicode text. (error -1700)
但是来自文件夹 Destination 和 name 的日志确实有效:
2021-03-13 09:28:02.750713+0100 Media Folder Creator[1571:39314] file:///Users/name/Desktop/
和:
2021-03-13 09:28:02.753207+0100 Media Folder Creator[1571:39314] folderName123
Xcode 中的文本字段连接到 nameOfFolder。模型键路径:nameOfFolder
我不知道错误在哪里。谢谢你的帮助。
解决方案
问题是nameOfFolder
一个NSString
对象,您必须通过强制将其桥接到 AppleScript text
:
make new folder at folderDestination with properties {name:nameOfFolder as text}
但是由于您已经在 Cocoa 世界中,因此使用NSFileManager
.
on startButton:sender
set folderDestination to POSIX path of (choose folder)
log folderDestination
log nameOfFolder
set fileManager to current application's NSFileManager's defaultManager()
set {success, fmError} to fileManager's createDirectoryAtPath:(folderDestination & nameOfFolder as text) withIntermediateDirectories:false attributes:(missing value) |error|:(reference)
if success is false then log fmError's localizedDescription()
end startButton:
推荐阅读
- c# - 保存购买的物品统一
- javascript - React:如何将字符串发送到函数组件
- python - 时间序列预测中的负值
- javascript - 如何获得ajax请求的结果?
- angular - 无法从 asp.net core api 获取数据到角度 6
- kubernetes - 面向用户的服务的 Istio 请求路由不适用于 ingress-gateway
- python - 使用类计算年龄
- ios - 如何不使用 App Store 或 Enterprise 帐户在内部发布 IOS 应用程序?
- python - 使用已经存在的值的 beautifulsoup 将标签插入到 html 中
- mysql - 错误 1026 写入文件 'mysql-bin' 时出错