我正在使用 Araxis 提供的 applescripts,以便我可以使用 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
当我硬编码路径而不是使用"."
时,警告消失了。我已经尝试过 pre-pending file:///
,但POSIX path of
正在考虑将其中一个斜杠作为转义字符,因此路径变为file:/Users/...
,然后生成一个错误,因为它具有未知的模式(因为第二个斜杠已被删除)。所以,我的问题是,获取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