4

次のコードでapplescriptを使用して、デスクトップウィンドウの境界を取得しようとしています:

tell application "Finder"
    get bounds of window of desktop
end tell

「実行エラー: Finder でエラーが発生しました: デスクトップのウィンドウの境界を取得できません (-1728)」というメッセージが表示され続けます。

私はライオンを実行しています。どうすればこれを機能させることができますか?

4

1 に答える 1

6

デスクトップとウィンドウは2つの異なるものです。デスクトップは、実際にはにあるフォルダですMacintosh HD:Users:yourusername:Desktop:。Finderでウィンドウの境界を取得する場合は、問題のウィンドウを特定する必要があります。このようなものが機能します...

tell application "Finder"
    set windowCount to (count windows)
    if windowCount > 0 then
        set windowBounds to bounds of window 1 --> Note the '1'
        return windowBounds
    end if
end tell

開いているウィンドウがない場合、Applescriptはエラーを返すため、実際に開いているウィンドウがあるかどうかを確認することに注意してください。

画面の境界を取得しようとしている場合、必要なのは次のことだけです...

tell application "Finder"
    get bounds of window of desktop --> weird but that's Applescript for you
end tell
--> Result: {0, 0, 1440, 900}

Finderを終了または非表示にする機能が有効になっている場合、上記は機能しません。

于 2012-07-14T23:41:57.760 に答える