POSIX файл "." поскольку псевдоним вызывает "CFURLGetFSRef был передан этот URL, у которого нет схемы" предупреждение
Я использую applecripts, предоставленный Araxis, чтобы я мог использовать Merge для обработки моей команды 'git diff HEAD`.
Однако с тех пор, как я перешел на Mountain Lion, каждый раз, когда я запускаю команду, я получаю предупреждение:
CFURLGetFSRef was passed this URL which has no scheme
(the URL may not work with other CFURL routines): .
В скрипте проблема возникает
set _file2 to (POSIX path of (POSIX file "." as alias)) & _file2
Когда я жестко запрограммировал путь вместо использования "."
предупреждение уходит. Я пробовал предварительно в ожидании file:///
, но POSIX path of
рассматривает один из слэшей как побег, и поэтому путь становится file:/Users/...
который затем генерирует ошибку из-за наличия неизвестной схемы (так как второй слеш был удален). Итак, мой вопрос в том, как правильно (сейчас, в Mountain Lion), чтобы получить POSIX file
для текущего местоположения?
добавление полного скрипта
#!/usr/bin/osascript
# This script is required to reorder the parameters sent by Git, so that they may be passed into the Merge Applescript API
on run args
tell application "Araxis Merge"
set _file1 to item 2 of args as text
set _file2 to item 5 of args as text
if not _file1 starts with "/"
set _file1 to (POSIX path of (POSIX file "." as alias)) & _file1
end if
if not _file2 starts with "/"
set _file2 to (POSIX path of (POSIX file "." as alias)) & _file2
end if
set _document to compare {_file1, _file2}
tell _document
activate
end tell
repeat while exists _document
delay 1
end repeat
end tell
end run
рабочий раствор (спасибо @adayzdone)
#!/usr/bin/osascript
# This script is required to reorder the parameters sent by Git, so that they may be passed into the Merge Applescript API
on run args
tell application "Araxis Merge"
set _file1 to item 2 of args as text
set _file2 to item 5 of args as text
if not _file1 starts with "/"
set _file1 to (POSIX path of (POSIX file (do shell script "pwd") as alias)) & _file1
end if
if not _file2 starts with "/"
set _file2 to (POSIX path of (POSIX file (do shell script "pwd") as alias)) & _file2
end if
set _document to compare {_file1, _file2}
tell _document
activate
end tell
repeat while exists _document
delay 1
end repeat
end tell
end run
2 ответа
Мне нужен путь к текущему каталогу оболочки, в которой выполняется команда
Это работает для вас?
set xxx to do shell script "pwd"
osascript показывает предупреждение каждый раз, когда относительный путь преобразуется в псевдоним 10.8.
$ touch test.txt
$ osascript -e 'POSIX file "test.txt" as alias'
2012-12-19 09:43:49.300 osascript[16581:707] CFURLGetFSRef was passed this URL which has no scheme (the URL may not work with other CFURL routines): test.txt
alias HD:private:tmp:test.txt
Вот еще один способ конвертировать пути:
osa() {
osascript - "$PWD" "$@" <<'END'
on run argv
repeat with f in items 2 thru -1 of argv
if f does not start with "/" then set f to item 1 of argv & "/" & f
posix file f as alias
end
end
END
}
osa ~/Documents/ 1.txt
Вы также можете просто перенаправить stderr.
osa() {
osascript - "$@" <<END 2> /dev/null
on run argv
POSIX file (item 1 of argv) as alias
end
END
}
osa test.txt