2017-10-20 113 views
0

當涉及到AppleScript並且在斷開外部顯示器時與一臺Mac筆記本電腦有問題時,我是一個完整的noob。斷開外部監視器後,打開文檔(如word和excel文件)將從屏幕移出,並且無法將其拖回到視圖中。用於收集所有窗口的AppleScript錯誤:期望行結束但發現未知令牌

OS X埃爾卡皮坦版本10.11.6(15G1510)

我發現,要收集所有打開的窗口,使他們進入查看監視器上一個AppleScript,但每次我得到一個錯誤。

語法錯誤:預計行結束但找到未知標記。

下面是腳本:

#!/usr/bin/osascript 

tell application "Finder" 

    -- get desktop dimensions dw = desktop width; dh = desktop height 
    set db to bounds of window of desktop 
    set {dw, dh} to {item 3 of db, item 4 of db} 
end tell 

tell application "System Events" 
    repeat with proc in application processes 
     tell proc 
      repeat with win in windows 
       -- get window dimensions (w = width; h = height) 
       set {w, h} to size of win 

       -- get window postion (l = left of window; t = top of window) 
       set {l, t} to position of win 

       -- nh = new window height; nw = new window width 
       set {nh, nw} to {h, w} 

       -- window width is bigger than desktop size, 
       -- so set new window width to match the desktop 
       if (w > dw) then ¬ 
        set nw to dw 

       -- window height is bigger than the desktop size (minus menu bar), 
       -- so set new window height to be desktop height - 22 pixels 
       if (h > dh - 22) then ¬ 
        set nh to dh - 22 

       -- r = right coordinate of window; b = bottom coordinate of window 
       set {r, b} to {l + nw, t + nh} 

       -- nl = new left coordinate; nt = new top coordinate 
       set {nl, nt} to {l, t} 

       -- left coordinate is off screen, so set new left coordinate 
       -- to be 0 (at the left edge of the desktop) 
       if (l < 0) then ¬ 
        set nl to 0 

       -- top coordinate is above bottom of menu bar (22 pixels tall), 
       -- so set new top coordinate to be 22 
       if (t < 22) then ¬ 
        set nt to 22 

       -- right coordinate extends beyond desktop width, 
       -- so set new left coordinate to be desktop width - window width 
       if (r > dw) then ¬ 
        set nl to dw - nw 

       -- bottom coordinate extends beyond desktop height, 
       -- so set new top coordinate to be desktop height - window height 
       if (b > dh) then ¬ 
        set nt to dh - nh 

       -- if we have calculated a new top or left coordinate, reposition window 
       if (l â‰" nl or t "â‰" nt) then ¬ 
        set position of win to {nl, nt} 

       -- if we have calculated a new height or width, resize window 
       if (h "â‰" nh or w "â‰" nw) then ¬ 
        set size of win to {nw, nh} 
      end repeat 
     end tell 
    end repeat 
end tell 

任何幫助或建議將不勝感激。

回答

0

這是一個文本編碼問題。

  • 更換¬¬

還有另外一個錯誤,但我不知道它代表什麼我想這是所以

  • 更換"â‰"⌥=
+0

謝謝!你的建議奏效,你的部分取得了完美的勝利。非常感謝幫助。 – rae004

相關問題