Applescript 获取名称异常

Applescript get name exception

在我的一个脚本中,我需要文件名:

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" 到达。我能以某种方式欺骗它以在 return 中获得 "soso/lala.txt" 吗?

文件名中的冒号和斜杠在 AppleScript 中容易出错,因为冒号是 HFS 路径(默认 AppleScript 类型)中的路径分隔符,而斜杠是 POSIX 路径中的路径分隔符

两条建议:

  1. 使用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
    
  2. 使用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