POSIX文件“。”作为别名导致“CFURLGetFSRef传递此URL没有方案”警告

时间:2012-10-08 07:25:46

标签: git merge applescript araxis

我正在使用Araxis提供的Applecripts,以便我可以使用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/...,然后生成错误,因为它有一个未知的schema(因为删除了第二个斜杠)。所以,我的问题是,为当前位置获取POSIX file的正确方法(现在,在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

2 个答案:

答案 0 :(得分:3)

osascript每次在10.8上显示relative path is converted to an alias时都会显示警告。

$ 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

答案 1 :(得分:2)

  

我需要的是shell当前目录的路径   该命令正在运行

这对你有用吗?

set xxx to do shell script "pwd"