git - POSIX 文件 "."作为别名导致 "CFURLGetFSRef was passed this URL which has no scheme"警告

标签 git merge applescript araxis

我正在使用 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

当我对路径进行硬编码而不是使用 "." 时,警告消失了。我已经尝试在 file:/// 之前添加,但是 POSIX path of 正在考虑将其中一个斜杠作为转义字符,因此路径变为 file:/Users/... 然后生成一个错误,因为有一个未知的模式(因为第二个斜杠被删除)。所以,我的问题是,获取当前位置的 POSIX 文件 的正确方法是什么(现在,在 Mountain Lion 中)?

添加完整脚本

#!/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

最佳答案

osascript 每次显示警告 relative path is converted to an alias 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

关于git - POSIX 文件 "."作为别名导致 "CFURLGetFSRef was passed this URL which has no scheme"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12777082/

相关文章:

macos - git:尝试将存储库推送到 Mac 上的 Amazon Elastic Beanstalk 时, 'aws.push' 不是 git 命令

mysql - 合并两个 mysql 表

macos - 使用 osascript 命令在 Bash 中组合变量以形成发送到 AppleScript 的命令

javascript - 将自动变量传递给 JavaScript

iphone - UI自动化工具可以从命令行运行吗?

Git:拒绝通过推送删除远程分支(如 receive.denyDeletes),但前提是分支未完全 merge

git - 修改不在分支顶端的提交的最快、最简单的方法?

git - 如果 git 文件包含损坏的松散对象,是否可以推送非推送的提交?

在市集合并两个结帐

python - 合并一个数据帧中与另一数据帧中的特定列不匹配的行 Python Pandas