Update FetchLyric

Update FetchLyric

-- FetchLyric
-- DESCRIPTION: 让iTunes内当前被选中的曲目自动下载并保存歌词，若歌词已存在将被忽略，支持Growl通知
-- AUTHOR: JinnLynn http:://jeeker.net
-- LAST UPDATED: 2012-05-04
-- INTRO PAGE: http://jeeker.net/fetch-lyric-for-itunes/
-- REF: Martian http://blog.4321.la/articles/2012/01/27/use-applescript-to-set-itunes-lyrics/
property scriptName : "FetchLyric"
property baseURL : "http://lyrics.sinaapp.com/"
property isGrowlRunning : false
property statusDesc : {"歌词已存在，无需再获取。", "歌词获取成功。", "歌词获取失败。", "未选择歌曲。"}
property STATUS_LYRIC_EXIST : 1
property STATUS_LYRIC_SUCCESS : 2
property STATUS_LYRIC_FAIL : 3
property STATUS_LYRIC_UNSELECTED : 4

tell application "System Events"
set isGrowlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

script growl
on growlNotify(artist, title, status)
    if isGrowlRunning = false then return
    tell application id "com.Growl.GrowlHelperApp"
        if title = "" then set title to "unknown"
        set the_title to title
        if artist is not equal to "" then set the_title to artist & " - " & the_title
        set the_desc to item status of statusDesc
        set the allNotificationsList to {scriptName}
        set the enabledNotificationsList to {scriptName}
        register as application ¬
            scriptName all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "iTunes"
        notify with name ¬
            scriptName title ¬
            the_title description ¬
            the_desc application name scriptName
        -- 尝试使用歌曲封面作为Growl图标出错
    end tell
end growlNotify
end script

tell application "iTunes"
if selection is {} then
    tell growl to growlNotify("", "", STATUS_LYRIC_UNSELECTED)
    return
end if
set k to count (item of selection)
set i to 1
repeat
    set theTrack to (item i of selection)
    set this_artist to (get artist of theTrack)
    set this_title to (get name of theTrack)
    set this_lyric to (get lyrics of theTrack)
    -- set this_artwork to data of artwork 1 of theTrack

    set fetch_status to STATUS_LYRIC_FAIL

    if length of this_lyric < 1 then
        -- 只有当歌曲中未存在歌词时才尝试获取歌词
        set requestData to "title=" & this_title & "&artist=" & this_artist
        set songLyrics to do shell script "curl -d '" & requestData & "' " & baseURL
        if length of songLyrics > 1 then
            -- 歌词成功获取
            set lyrics of theTrack to songLyrics
            set fetch_status to STATUS_LYRIC_SUCCESS
        end if
    else
        set fetch_status to STATUS_LYRIC_EXIST
    end if

    tell growl to growlNotify(this_artist, this_title, fetch_status)

    set i to i + 1
    if i > k then exit repeat
end repeat
-- 如果Growl未运行则显示对话框
if isGrowlRunning = false then
    display dialog return & "歌词获取结束！" buttons {"确定"} default button 1 with icon 1 giving up after 5 with title scriptName
end if
end tell

FasdUAS 1.101.10
k
l FetchLyric		 FetchLyric

l
B< DESCRIPTION: ?iTunes????????????????????????????????Growl??
x DESCRIPTION: iTunesQ_SRM	N-vfvRN}^vO[XkLkL][XW(\_uee/cGrowlw
l*$ AUTHOR: JinnLynn http:://jeeker.netH AUTHOR: JinnLynn http:://jeeker.net
l LAST UPDATED: 2012-05-042 LAST UPDATED: 2012-05-04
l<6 INTRO PAGE: http://jeeker.net/fetch-lyric-for-itunes/l INTRO PAGE: http://jeeker.net/fetch-lyric-for-itunes/
l ! a[ REF: Martian http://blog.4321.la/articles/2012/01/27/use-applescript-to-set-itunes-lyrics/!"" REF: Martian http://blog.4321.la/articles/2012/01/27/use-applescript-to-set-itunes-lyrics/#$
#j%0
scriptname
scriptName
%m&&''FetchLyric$()
(j*0baseurlbaseURL
*m++,,4http://lyrics.sinaapp.com/)-.
-j/ 0isgrowlrunningisGrowlRunning
/m
boovfals.01
0j	20
statusdesc
statusDesc
2J	3345
4m
6677kL][XW(eQS0589
8m
::;;kL̓SbR09<=
<m>>??kL̓SY1%0=@
@m
AABBg*	bkLf01CD
CjE(0status_lyric_existSTATUS_LYRIC_EXIST
EmDFG
FjH,0status_lyric_successSTATUS_LYRIC_SUCCESS
HmGIJ
IjK&0status_lyric_failSTATUS_LYRIC_FAIL
KmJLM
LjN20status_lyric_unselectedSTATUS_LYRIC_UNSELECTED
NmMOP
OlPQR
QlS
SOTU
TrVW
V?XY
XlZ
ZI[
.corecnte********
[l\
\6]^
]2

prcs
^=_`
_1

bnid
`maabb0com.Growl.GrowlHelperApp
Ym
Wo 0isgrowlrunningisGrowlRunning
Umccsevsalis
MacOSXLionH+uSystem Events.app(Z	 CoreServices?H3uhg;MacOSXLion:System:Library:CoreServices:System Events.app$System Events.app
MacOSXLion-System/Library/CoreServices/System Events.app/Rde
dlefg
fh&h	0growl
hiij
iIk0growlnotifygrowlNotifyklm
lo
0artistmno
no	0titleop
po
0status
jkqqrs
rZtu
t=vw
vo 0isgrowlrunningisGrowlRunning
wm
boovfals
uL
sx
xOyz
yk{{|}
|Z&~
~=
o	0title
m
r"
m unknown
o	0title}
r'*
o'(	0title
o
0	the_title
Z+<
>+.
o+,
0artist
m,-
r18
b16
b14
o12
0artist
m23 -
o45
0	the_title
o
0	the_title
r=G
n=E
4BE

cobj
oCD
0status
o=B0
statusdesc
statusDesc
o0the_desc
rHQ
JHO
oHM0
scriptname
scriptName
l
o,0allnotificationslistallNotificationsList
rR[
JRY
oRW0
scriptname
scriptName
l
o40enablednotificationslistenabledNotificationsList
I\m
.registernullnull

appl
l	^c
o^c0
scriptname
scriptName

anot
l
de
ode,0allnotificationslistallNotificationsList

dnot
l
fg
ofg40enablednotificationslistenabledNotificationsList

iapp
mhiiTunes
In
.notifygrnullnull

name
l	pu
opu0
scriptname
scriptName

titl
l	xy
oxy
0	the_title

desc
l	|}
o|}0the_desc

appl
o~0
scriptname
scriptName
l ??????????Growl????( \Ou(kLf\bO\N:GrowlVhQ
z5

capp
m0com.Growl.GrowlHelperApp
kfrmID  g
l
lb
Ob
k"a
Z"G
="(
1"%

sele
J%'
k+C
O+@
I3?0growlnotifygrowlNotify
m45
m56
o6;20status_lyric_unselectedSTATUS_LYRIC_UNSELECTED
o+0~~	0growl}
LAC||}
rHS
IHQ{z
{.corecnte********
lHMyx
nHM
mKMw
w
cobj
1HKv
v
seleyxz
ouu0k
rTW
mTUtt
oss0i
TX'
k]"
r]e
l]crq
n]c
4`cp
p
cobj
oaboo0i
1]`n
n
selerq
omm0thetracktheTrack

	rfn
lfj
lk

efj
nfj
1gij
j
pArt
ofgii0thetracktheTracklk
ohh0this_artist

roy
lougf
eou
nou
1pte
e
pnam
oopdd0thetracktheTrackgf
occ0
this_title
rz
lzba
ez
nz
1{`
`
pLyr
 oz{__0thetracktheTrackba
o^^0
this_lyric!"
!l]#$]#82 set this_artwork to data of artwork 1 of theTrack$%%d set this_artwork to data of artwork 1 of theTrack"&'
&l\[Z\[Z'()
(r*+
*oYY&0status_lyric_failSTATUS_LYRIC_FAIL
+oXX0fetch_status),-
,lWVUWVU-./
.Z01T2
0A34
3n56
51S
S
leng
6oRR0
this_lyric
4mQQ
1k7789
8lP:;P: ???????????????????;<<( Sg	_SkLfN-g*[XW(kLebM\ՃSkL9=>
=r?@
?bAB
AbCD
CbEF
EmGGHHtitle=
FoOO0
this_title
DmIIJJ&artist=
BoNN0this_artist
@oMM0requestdatarequestData>KL
KrMN
MILOK
L.sysoexecTEXTTEXT
ObPQ
PbRS
RbTU
TmVVWWcurl -d '
UoJJ0requestdatarequestData
SmXXYY'
QoII0baseurlbaseURLK
NoHH0
songlyrics
songLyricsLZG
ZZ[\FE
[?]^
]n_`
_1D
D
leng
`oCC0
songlyrics
songLyrics
^mBB
\kaabc
blAdeAd
 ??????eff kLbRScgh
grij
io@@0
songlyrics
songLyrics
jnkl
k1?
?
pLyr
lo>>0thetracktheTrackhm=
mrno
no<<,0status_lyric_successSTATUS_LYRIC_SUCCESS
oo;;0fetch_status=FEGT
2rpq
po::(0status_lyric_existSTATUS_LYRIC_EXIST
qo990fetch_status/rs
rl876876stu
tOvw
vI5x450growlnotifygrowlNotifyxyz
yo330this_artistz{|
{o220
this_title|}1
}o000fetch_status14
wo//	0growlu~
~l.-,.-,
r
[
o++0i
m**
o))0i(
Z"'&
?
o%%0i
o$$0k
S'&(
l((## ??Growl?????????" YgGrowlg*ЈLRf>y:[hF"
Z(a!
=(/
o(- 0isgrowlrunningisGrowlRunning
m-.
boovfals
I2]
.sysodlogaskrTEXT
b29
o25

ret
m58kL̓S~g_

btns
J<A
m<?xn[

dflt
mDE

disp
mHI

givu
mLO

appr
oRW0
scriptname
scriptName! "
mhookalisH
MacOSXLionH+
iTunes.app`t5	 Applications?HsX#MacOSXLion:Applications:iTunes.app
iTunes.app
MacOSXLionApplications/iTunes.app/&+

	0
scriptname
scriptName0baseurlbaseURL 0isgrowlrunningisGrowlRunning0
statusdesc
statusDesc(0status_lyric_existSTATUS_LYRIC_EXIST,0status_lyric_successSTATUS_LYRIC_SUCCESS&0status_lyric_failSTATUS_LYRIC_FAIL20status_lyric_unselectedSTATUS_LYRIC_UNSELECTED	0growl
.aevtoappnull****0k0i0thetracktheTrack0this_artist0
this_title0
this_lyric0fetch_status
boovtrue6:>A
h	0growl&+
0
scriptname
scriptName0baseurlbaseURL 0isgrowlrunningisGrowlRunning0
statusdesc
statusDesc(0status_lyric_existSTATUS_LYRIC_EXIST,0status_lyric_successSTATUS_LYRIC_SUCCESS&0status_lyric_failSTATUS_LYRIC_FAIL20status_lyric_unselectedSTATUS_LYRIC_UNSELECTED	0growl
.aevtoappnull****
boovtrue
.aevtoappnull****
kbQ)caGIVX

prcs

bnid
.corecnte********

sele0growlnotifygrowlNotify

cobj0k0i0thetracktheTrack

pArt0this_artist

pnam0
this_title

pLyr0
this_lyric0fetch_status

leng0requestdatarequestData
.sysoexecTEXTTEXT0
songlyrics
songLyrics

ret

btns

dflt

disp

givu

appr

.sysodlogaskrTEXTc*-[,\Z81jjEcUOA*,jvb*bm+
UOhYhO*,,jEOkEOhZ*,/EO,EE`Oa,EE`Oa,EE`ObE`O_a,kVa_%a%_%E`Oa_%a%b%jE`O_a,k_a,FObE`YhYbE`Ob*___m+
UOkEOYh[OY7Obf0_a%a a!kva"ka#ka$a%a&ba'(YhU0growlnotifygrowlNotifyj0growlnotifygrowlNotify
0artist	0title
0status
0artist	0title
0status
0	the_title0the_desc,0allnotificationslistallNotificationsList40enablednotificationslistenabledNotificationsList

capp
kfrmID

cobj

appl

anot

dnot

iapp
.registernullnull

name

titl

desc
.notifygrnullnullbfhYhO)0rEYhOEO%%EYhOb/EObkvEObkvEO*bO*baabOPU

cSrcJ
kfrmID

cUsP!B
kfrmID

cFlT!R
kfrmID  hY9Rlr~NPZNN*Q[ R+N`NHbN
t
SꉁO`N_Nh7v[
ba?aY)mmwҐO`S
bwSNRN
[f
bv_Nvn)N`g
]
g`O`_q6e>_

r1wvRl geb[mA
SꉁO`NN*w<y^[ bvr1\1g	aNI
bNRl SvOOW(Nw
Nonbc$baO`
e>W(bbK_Ñ O`vw_

YgbvWZ_:N`' ON
\_O$[NO`
O`N
n)gcБ
b}q6_Y*`% f[`O`ascr
ޭ


Update URLs that open at the office

Update URLs that open at the office

set myTabs to {"https://github.com/search?utf8=%E2%9C%93&q=assignee%3Apalcu+state%3Aopen&type=Issues&ref=searchresults", "https://mail.google.com/mail/u/1/?shva=1#inbox", "https://drive.google.com/a/hootsuite.com/#folders/0BwuFsHJDxJWPYmxXQ1VQVlN6T2M"}
tell application "Google Chrome"
	activate
	repeat with i in myTabs
		open location i
	end repeat
end tell

set myTabs to {"http://app.getsentry.com/", "http://github.com/uberVU/thehole/issues/assigned/palcu?direction=desc&labels=&milestone=&page=1&sort=updated&state=open/", "https://mail.google.com/mail/u/1/?shva=1#inbox", "https://drive.google.com/a/hootsuite.com/#folders/0BwuFsHJDxJWPYmxXQ1VQVlN6T2M"}
tell application "Google Chrome"
	activate
	repeat with i in myTabs
		open location i
	end repeat
end tell


moveForMon.applescript, from darwin13

moveForMon.applescript, from darwin13

property DEF_ALL : false
property DEF_DEBUG_LEVEL : 1

on moveForMon(pars)

	set {all, debug_level} to {DEF_ALL, DEF_DEBUG_LEVEL}
	try
		set all to all of pars
	end try
	try
		set debug_level to debug_level of pars
	end try

	-- debug mode
	if debug_level > 0 then
		log "debug mode = " & debug_level
		if debug_level > 1 then
			display dialog "debug mode = " & debug_level
		end if
	end if

	-- set monitoring tools' positions
	-- SimpleFloatingClock
	set w_sfcCEST to 1
	set w_sfcJST to 2

	-- XRG
	set w_XRG to 1

	-- set monitoring tool's name
	-- GeekTool
	set s_gtCal to "gcalCal"
	set s_gtGcal to "gcalList"
	set s_gtTask to "gtasklist"
	set s_gtPs to "myps"

	-- x posiiotn for monitoring
	set ledge to -160
	set ledgeSFCoffset to 20

	-- y positions
	set y_sfcCEST to 30
	set y_sfcJST to y_sfcCEST + 100
	set y_gtCal to y_sfcJST + 105
	set y_gtGcal to y_gtCal + 115
	set y_gtTask to y_gtGcal + 175
	set y_gtPs to y_gtTask + 85
	set y_XRG to y_gtPs + 75

	-- app to be excepted
	set expApp to {"XRG"}

	-- app to be half size, in left monitor (0.7 times full)
	set halfSizeApp_L to {}

	-- app to be half size, in right monitor (0.7 times full)
	set halfSizeApp_R to {"AdobeReader"}

	-- app only to be moved, in left monitor
	set noResizeApp_L to {}

	-- app only to be moved, in right monitor
	set noResizeApp_R to {"Finder", "Skype", "Microsoft Word", "Microsoft Excel", "Microsoft PowerPoint"}

	-- app to be moved left
	set app_L to {"firefox", "Evernote", "thunderbird", "thunderbird-bin", "Mail"}

	-- app to be moved right
	set app_R to {"iTerm"}

	-- get screen size
	tell application "Finder"
		set scriptPath to (path to me)'s folder as text
	end tell
	set windowSizeScpt to scriptPath & "windowSize.scpt"
	set windowSize to load script file windowSizeScpt

	-- main screen
	set svs to windowSize's getVisibleFrame(1, 1) --+1 is used to avoid edge, especially needed for y position
	set dPosX to (item 1 of svs) + 1
	set dPosY to (item 2 of svs) + 1
	set dWidth to item 3 of svs
	set dHeight to item 4 of svs

	-- try to get left screen
	set dPosX_L to dPosX + 1
	set dPosY_L to dPosY + 1
	try
		set svsL to windowSize's getVisibleFrame(-1, 1)
		set dPosX_L to (item 1 of svsL) + 1
		set dPosY_L to (item 2 of svsL) + 1
	end try

	-- try to get right screen
	set dPosX_R to dPosX + 1
	set dPosY_R to dPosY + 1
	try
		set svsR to windowSize's getVisibleFrame(dPosX + dWidth + 1, 1)
		set dPosX_R to (item 1 of svsR) + 1
		set dPosY_R to (item 2 of svsR) + 1
	end try

	-- move monitoring tools
	if dPosX_L < 0 then
		if debug_level > 0 then
			log "ledge to ledgeDual"
		end if
	else
		set ledge to dWidth + ledge
		if debug_level > 0 then
			log "ledge to ledgeSingle"
		end if
	end if

	tell application "System Events"
		-- SimpleFloatingClock
		try
			set appName to "SimpleFloatingClock"
			tell process appName
				tell window w_sfcCEST
					set size to {1000, 1000}
					set position to {ledge + ledgeSFCoffset, y_sfcCEST}
				end tell
				tell window w_sfcJST
					set size to {1000, 1000}
					set position to {ledge + ledgeSFCoffset, y_sfcJST}
				end tell
			end tell
		end try

		---- GeekTool
		--try
		--	--set appName to "GeekTool"
		--	set appName to "GeekTool Helper" -- for GeekTool 3
		--
		--	tell process appName
		--		set nW to number of windows
		--		--display dialog appName & " in process, nWindows=" & nW
		--		tell window w_gtCal
		--		end tell
		--		tell window w_gtGcal
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtGcal}
		--		end tell
		--		tell window w_gtTask
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtTask}
		--		end tell
		--		tell window w_gtPs
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtPs}
		--		end tell
		--	end tell
		--	--on error errMsg
		--	--	display dialog "ERROR: " & errMsg
		--end try

		-- XRG
		try
			set appName to "XRG"
			tell process appName
				tell window w_XRG
					set size to {1000, 2000}
					set position to {ledge, y_XRG}
				end tell
			end tell
		end try
	end tell

	-- GeekTool (should be outside of application "System Events", and use application "GeekTool Helper" ?)
	-- can't use position to geeklets
	tell application "GeekTool Helper" -- can not use appName (variable), which shows error at id?
		--geeklets
		repeat with g in geeklets
			tell g
				name
				if name is s_gtCal then
					set x position to ledge
					set y position to y_gtCal
				else if name is s_gtGcal then
					set x position to ledge
					set y position to y_gtGcal
				else if name is s_gtTask then
					set x position to ledge
					set y position to y_gtTask
				else if name is s_gtPs then
					set x position to ledge
					set y position to y_gtPs
				end if
			end tell
		end repeat
	end tell

	-- Move/Resize other windows
	if all then
		-- get application name
		tell application "System Events"
			set appList to (get name of every application process whose visible is true)
		end tell

		-- repeat for all app
		repeat with appName in appList
			if appName is not in expApp then
				tell application "System Events"
					try
						tell process appName
							set nW to number of windows
							repeat with i from 1 to nW
								if debug_level > 0 then
									log appName & " " & i
									if debug_level > 1 then
										display dialog appName & " " & i
									end if
								end if
								if appName is in halfSizeApp_L then
									if debug_level > 0 then
										log "half size left"
										if debug_level > 1 then
											display dialog "half size left"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, xsize:0.7, ysize:0.7, moveForMon:false, debug_level:debug_level})
								else if appName is in halfSizeApp_R then
									if debug_level > 0 then
										log "half size right"
										if debug_level > 1 then
											display dialog "half size right"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, xsize:0.7, ysize:0.7, moveForMon:false, debug_level:debug_level})
								else if appName is in noResizeApp_L then
									if debug_level > 0 then
										log "half size left"
										if debug_level > 1 then
											display dialog "half size left"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, resize:0, moveForMon:false, debug_level:debug_level})
								else if appName is in noResizeApp_R then
									if debug_level > 0 then
										log "move right"
										if debug_level > 1 then
											display dialog "move right"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, resize:0, moveForMon:false, debug_level:debug_level})
								else if appName is in app_L then
									if debug_level > 0 then
										log "move left full size"
										if debug_level > 1 then
											display dialog "move left full size"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, moveForMon:false, debug_level:debug_level})
								else if appName is in app_R then
									if debug_level > 0 then
										log "move right full size"
										if debug_level > 1 then
											display dialog "move right full size"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, moveForMon:false, debug_level:debug_level})
								end if
							end repeat
						end tell
					end try
				end tell
			end if
		end repeat
	end if
end moveForMon

on run
	moveForMon({})
end run

property DEF_ALL : false
property DEF_DEBUG_LEVEL : 1

on moveForMon(pars)

	set {all, debug_level} to {DEF_ALL, DEF_DEBUG_LEVEL}
	try
		set all to all of pars
	end try
	try
		set debug_level to debug_level of pars
	end try

	-- debug mode
	if debug_level > 0 then
		log "debug mode = " & debug_level
		if debug_level > 1 then
			display dialog "debug mode = " & debug_level
		end if
	end if

	-- set monitoring tools' positions
	-- SimpleFloatingClock
	set w_sfcCEST to 1
	set w_sfcJST to 2

	-- XRG
	set w_XRG to 1

	-- set monitoring tool's name
	-- GeekTool
	set s_gtCal to "gcalCal"
	set s_gtGcal to "gcalList"
	set s_gtTask to "gtasklist"
	set s_gtPs to "myps"

	-- x posiiotn for monitoring
	set ledge to -160
	set ledgeSFCoffset to 20

	-- y positions
	set y_sfcCEST to 30
	set y_sfcJST to y_sfcCEST + 100
	set y_gtCal to y_sfcJST + 105
	set y_gtGcal to y_gtCal + 115
	set y_gtTask to y_gtGcal + 175
	set y_gtPs to y_gtTask + 85
	set y_XRG to y_gtPs + 75

	-- app to be excepted
	set expApp to {"XRG"}

	-- app to be half size, in left monitor (0.7 times full)
	set halfSizeApp_L to {}

	-- app to be half size, in right monitor (0.7 times full)
	set halfSizeApp_R to {"AdobeReader"}

	-- app only to be moved, in left monitor
	set noResizeApp_L to {}

	-- app only to be moved, in right monitor
	set noResizeApp_R to {"Finder", "Skype", "Microsoft Word", "Microsoft Excel", "Microsoft PowerPoint"}

	-- app to be moved left
	set app_L to {"firefox", "Evernote", "thunderbird", "thunderbird-bin", "Mail"}

	-- app to be moved right
	set app_R to {"iTerm"}

	-- get screen size
	tell application "Finder"
		set scriptPath to (path to me)'s folder as text
	end tell
	set windowSizeScpt to scriptPath & "windowSize.scpt"
	set windowSize to load script file windowSizeScpt

	-- main screen
	set svs to windowSize's getVisibleFrame(1, 1) --+1 is used to avoid edge, especially needed for y position
	set dPosX to (item 1 of svs) + 1
	set dPosY to (item 2 of svs) + 1
	set dWidth to item 3 of svs
	set dHeight to item 4 of svs

	-- try to get left screen
	set dPosX_L to dPosX + 1
	set dPosY_L to dPosY + 1
	try
		set svsL to windowSize's getVisibleFrame(-1, 1)
		set dPosX_L to (item 1 of svsL) + 1
		set dPosY_L to (item 2 of svsL) + 1
	end try

	-- try to get right screen
	set dPosX_R to dPosX + 1
	set dPosY_R to dPosY + 1
	try
		set svsR to windowSize's getVisibleFrame(dPosX + dWidth + 1, 1)
		set dPosX_R to (item 1 of svsR) + 1
		set dPosY_R to (item 2 of svsR) + 1
	end try

	-- move monitoring tools
	if dPosX_L < 0 then
		if debug_level > 0 then
			log "ledge to ledgeDual"
		end if
	else
		set ledge to dWidth + ledge
		if debug_level > 0 then
			log "ledge to ledgeSingle"
		end if
	end if

	tell application "System Events"
		-- SimpleFloatingClock
		try
			set appName to "SimpleFloatingClock"
			tell process appName
				tell window w_sfcCEST
					set size to {1000, 1000}
					set position to {ledge + ledgeSFCoffset, y_sfcCEST}
				end tell
				tell window w_sfcJST
					set size to {1000, 1000}
					set position to {ledge + ledgeSFCoffset, y_sfcJST}
				end tell
			end tell
		end try

		---- GeekTool
		--try
		--	--set appName to "GeekTool"
		--	set appName to "GeekTool Helper" -- for GeekTool 3
		--
		--	tell process appName
		--		set nW to number of windows
		--		--display dialog appName & " in process, nWindows=" & nW
		--		tell window w_gtCal
		--		end tell
		--		tell window w_gtGcal
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtGcal}
		--		end tell
		--		tell window w_gtTask
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtTask}
		--		end tell
		--		tell window w_gtPs
		--			-- set size to {1000, 1000}
		--			set position to {ledge, y_gtPs}
		--		end tell
		--	end tell
		--	--on error errMsg
		--	--	display dialog "ERROR: " & errMsg
		--end try

		-- XRG
		try
			set appName to "XRG"
			tell process appName
				tell window w_XRG
					set size to {1000, 2000}
					set position to {ledge, y_XRG}
				end tell
			end tell
		end try
	end tell

	-- GeekTool (should be outside of application "System Events", and use application "GeekTool Helper" ?)
	-- can't use position to geeklets
	tell application "GeekTool Helper" -- can not use appName (variable), which shows error at id?
		--geeklets
		repeat with g in every «class gLet»
			tell g
				name
				if name is s_gtCal then
					set «class xpos» to ledge
					set «class ypos» to y_gtCal
				else if name is s_gtGcal then
					set «class xpos» to ledge
					set «class ypos» to y_gtGcal
				else if name is s_gtTask then
					set «class xpos» to ledge
					set «class ypos» to y_gtTask
				else if name is s_gtPs then
					set «class xpos» to ledge
					set «class ypos» to y_gtPs
				end if
			end tell
		end repeat
	end tell

	-- Move/Resize other windows
	if all then
		-- get application name
		tell application "System Events"
			set appList to (get name of every application process whose visible is true)
		end tell

		-- repeat for all app
		repeat with appName in appList
			if appName is not in expApp then
				tell application "System Events"
					try
						tell process appName
							set nW to number of windows
							repeat with i from 1 to nW
								if debug_level > 0 then
									log appName & " " & i
									if debug_level > 1 then
										display dialog appName & " " & i
									end if
								end if
								if appName is in halfSizeApp_L then
									if debug_level > 0 then
										log "half size left"
										if debug_level > 1 then
											display dialog "half size left"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, xsize:0.7, ysize:0.7, moveForMon:false, debug_level:debug_level})
								else if appName is in halfSizeApp_R then
									if debug_level > 0 then
										log "half size right"
										if debug_level > 1 then
											display dialog "half size right"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, xsize:0.7, ysize:0.7, moveForMon:false, debug_level:debug_level})
								else if appName is in noResizeApp_L then
									if debug_level > 0 then
										log "half size left"
										if debug_level > 1 then
											display dialog "half size left"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, resize:0, moveForMon:false, debug_level:debug_level})
								else if appName is in noResizeApp_R then
									if debug_level > 0 then
										log "move right"
										if debug_level > 1 then
											display dialog "move right"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, resize:0, moveForMon:false, debug_level:debug_level})
								else if appName is in app_L then
									if debug_level > 0 then
										log "move left full size"
										if debug_level > 1 then
											display dialog "move left full size"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, moveForMon:false, debug_level:debug_level})
								else if appName is in app_R then
									if debug_level > 0 then
										log "move right full size"
										if debug_level > 1 then
											display dialog "move right full size"
										end if
									end if
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, moveForMon:false, debug_level:debug_level})
								end if
							end repeat
						end tell
					end try
				end tell
			end if
		end repeat
	end if
end moveForMon

on run
	moveForMon({})
end run