Good Good Study, Day Day Up!

Happy Life, Happy Money!

Applescript--实现窗口平铺

IWRose posted @ 2011年4月01日 09:23 in 未分类 , 1794 阅读

这段代码花的时间较长。虽然功能没问题,但是代码结构很乱。算beta1版吧,之后applescript系统学习后在补充点功能,完善下代码。

 

以下代码供参考,支持错误修正与建议。 可以举一反三实现窗口左右,上下移动等等。

set front_app to (path to frontmost application as Unicode text)

tell application front_app

activate

if (count document) is equal to 0 then

set win_num to count window

else

set win_num to count document

end if

--count numbers of window

(*

--保存原窗口配置

set win_save to {}

repeat with a from 1 to win_num

set b to get bounds of window a

set win_save to win_save & {b}

end repeat

*)

set sqr_win_num to win_num ^ 0.5

if (sqr_win_num mod 1) is equal to 0 then

set y_num to sqr_win_num

set x_num to y_num

else

set y_num to sqr_win_num div 1

set x_num to y_num + 1

repeat while win_num is greater than (x_num * y_num)

set x_num to x_num + 1

end repeat

end if

set bounds of window 1 to {0, 0, 1280, 800}

set max_win_size to get bounds of window 1

set x_l_point to item 1 of max_win_size

set x_r_point to item 3 of max_win_size

set y_u_point to item 2 of max_win_size

set y_d_point to item 4 of max_win_size

set x_win_size to x_r_point - x_l_point

set y_win_size to y_d_point - y_u_point

--get each small window's size

set each_x_win_size to x_win_size / x_num

set each_y_win_size to y_win_size / y_num

-- set tmp to 0

set all to 0

repeat with j from 1 to y_num

repeat with i from 1 to x_num

set b to i - 1

set c to j - 1

set all to (all + 1)

set bounds of window all to {(x_l_point + b * each_x_win_size), (y_u_point + c * each_y_win_size), each_x_win_size * i, y_u_point + each_y_win_size * j}

end repeat

end repeat

--activate window 3

-->set bounds of window 1 to {x_l_point, y_u_point, , 700}

(*

repeat with a from 1 to win_num

set b to item a of win_save

set bounds of window a to b

end repeat

*)

end tell

  • 无匹配
  • 无匹配

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter