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"?
1 ответ
Решение
Двоеточие и косая черта в именах файлов подвержены ошибкам в 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