1

次の 2 行のコードを呼び出すシェル スクリプトを使用しています。

iname=$(ls -d -1 $PWD/*jpg) 
osascript -e 'tell app "Finder" to set desktop picture to POSIX file \"$iname\"'

ここで、iname は変数で、必要な画像への絶対パスです。私が読んだことから、これは osascripts に変数を渡す方法です。しかし、これらの2行を実行しようとすると、このエラーが発生します

55:56: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)

誰かがこれを修正する方法を説明できますか?

4

2 に答える 2

2

一重引用符で囲まれた変数を展開しようとしています。これを試して:

osascript -e 'tell app "Finder" to set desktop picture to POSIX file "'"$iname"\"
于 2013-11-18T20:34:13.333 に答える
0

明示的な実行ハンドラーを使用して、コマンド ライン引数を取得することもできます。

osascript -e'on run {a}
    tell app "finder" to set desktop picture to posix file a
end' "$iname"`

パスを相対パスにできる場合は、GNUreadlinkを使用して絶対パスに変換できます。

osascript -e'on run {a}
    tell app "finder" to set desktop picture to posix file a
end' "$(greadlink -f "$iname")"

絶対パスのリストをスクリプトに渡す必要がある場合は、次のようにすることができます。

osascript -e'on run a
    set l to {}
    repeat with f in a
        set end of l to posix file f
    end
    l
end' "$@"

パスのリストをスクリプトに渡し、相対パスを絶対パスに変換する必要がある場合は、次のようにすることができます。

osascript -e'on run {a}
    set l to {}
    repeat with f in (get paragraphs of a)
        set end of l to posix file f
    end
    l
end' "$(greadlink -f "$@")"
于 2015-09-12T10:40:58.213 に答える