applescript - Applescript 获取名称异常
问题描述
在我的一个脚本中,我需要文件名:
set input to choose file multiple selections allowed yes
tell application "System Events"
set {nameInfo, sourcePath} to {name of item 1 of input, POSIX path of container of item 1 of input}
end tell
但是如果文件名中有一个“/”,例如“soso/lala.txt”,则名称返回为“soso:lala.txt”。我也试过:
do shell script "basename " & item 1 of input
但随后只有“lala.txt”到达。我可以以某种方式欺骗它以得到“soso/lala.txt”作为回报吗?
解决方案
文件名中的冒号和斜杠在 AppleScript 中容易出错,因为冒号是 HFS 路径(默认 AppleScript 类型)中的路径分隔符,而斜杠是 POSIX 路径中的路径分隔符
两个建议:
利用
displayed name
set input to choose file with multiple selections allowed tell application "System Events" set {nameInfo, sourcePath} to {displayed name of item 1 of input, POSIX path of container of item 1 of input} end tell
使用
Finder
set input to choose file with multiple selections allowed tell application "Finder" set {nameInfo, sourcePath} to {name of item 1 of input, POSIX path of (container of item 1 of input as text)} end tell
推荐阅读
- python - 为什么调试器不能在 pycharm 中工作?
- string - 删除前导空格在 Bash 中不起作用
- reactjs - AntD - 仅使用文本和索引的列渲染
- c# - 在不使用堆栈的情况下创建精简 MQTT 发布者(操作方法)
- scala - 使用 spark 检查列的数据类型
- python - 如何为列表中的每个项目移动字符串的一部分
- jquery - 组合 Bootstrap 4 下拉和折叠时的奇怪行为
- java - 计算二维数组中每一列的平均值的函数。线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:3
- python - 如何以简单的方式删除所有不和谐角色?
- python - 如何解决“'xmlrpc' not found since 'xmlrpc' is not a package”的问题?