2010-10-07 62 views
0

自從我處理了Applescript以來,這已經過了很多年了,所以在這裏進行了一些高級的道歉操作。用Appleccript記錄窗口的邊界(尺寸)

使用下面的代碼片段,我可以調整窗口大小

tell application "BBEdit" 
    activate 
    set the bounds of the first window to {100, 0, 700, 700} 
end tell 

我感興趣的是使用類似的語句來讀取,然後登錄第一窗口的範圍。我試圖

tell application "BBEdit" 
    activate 
    log (the bounds of the first window) 
    set wSize to the bounds of the first window 
    log wSize 
end tell 

但事件日誌中列出

(*bounds of window 1*) 
每次

。我期待更多的東西

{100, 0, 700, 700} 

我最終的目標是創建一個變量,其中包含窗口邊界,並以編程方式操縱值。第一步是學習如何正確記錄數值。

那麼,如何在Apple的腳本編輯器中記錄窗口應用程序的邊界。

回答

1

使用get ...

tell application "BBEdit" 
    log (get bounds of window 1) 
end tell 
--> Log: (*332, 44, 972, 896*) 
1

嘗試將其強制轉換爲列表,然後將其記錄下來。

1

一個重要的applescript規則...只告訴應用程序執行它的applescript字典中的東西。如果命令不在其字典中,那麼應用程序不會知道該命令,並且您可能會得到奇怪的結果(如果它編譯的話)。在你的情況下,「日誌」命令是一個標準的applescript命令,而不是BBEdit命令。所以當你得到奇怪的結果時,首先要嘗試的是將「非應用程序」命令移出應用程序tell block。

因此,嘗試在BBEdit tell塊內設置邊界(第一個窗口的邊界),然後在tell區塊外面記錄邊界。