6

Merge を使用して「git diff HEAD」コマンドを処理できるように、Araxis が提供する AppleScript を使用しています。

ただし、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が、スラッシュの 1 つをエスケープ文字と見なしているため、パスがfile:/Users/...になり、スキーマが不明であるというエラーが生成されます (2 番目のスラッシュが削除されたため)。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
4

2 に答える 2

5

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
于 2012-10-08T08:56:34.757 に答える
3

必要なのは、コマンドが実行されているシェルの現在のディレクトリへのパスです

これはうまくいきますか?

set xxx to do shell script "pwd"
于 2012-10-08T16:06:17.990 に答える