use List to format query

use List to format query

-- BBEdit_upgrade_SQL_Query_to_newer_format({})
-- Dan Shockley, NYHTC
-- BBEdit - upgrade SQL Query to newer format

(*
HISTORY:
	1.2 - 2018-05-22 ( dshockley ): modified to also convert the query to use List to separate the components of the query.
	1.1 - 2017-12-11 ( dshockley ): disable the usually no-longer-needed SQL_EscapeString, but WARN and comment, since it might sitll be needed when using with something OTHER THAN SQL_Where criteria.
	1.0 - 2017-09-15 ( dshockley ): first created.
*)

on run
	BBEdit_upgrade_SQL_Query_to_newer_format({})
end run

--------------------
-- START OF CODE
--------------------

on BBEdit_upgrade_SQL_Query_to_newer_format({})

	set regexSearch_SQL_Table to "Quote *\\( *TableNameOfField *\\( *([^\\)]+) *\\) *\\)"
	set regexReplace_SQL_Table to "SQL_Table ( \\1 )"

	set regexSearch_SQL_Field to "Quote *\\( ?FieldNameShort *\\( *([^\\)]+) *\\) *\\)"
	set regexReplace_SQL_Field to "SQL_Field ( \\1 )"

	set regexSearch_WhereEqualsClause to "^([\\t ]*)& *SQL_Field *\\( *([^\\)]+) *\\)
[\\t ]*& \" *= *\"
[\\t ]*& ([^\\r]+)\\r"

	set regexReplace_WhereEqualsClause to "\\1\\& SQL_Where ( \\2 ; \"=\" ; \\3 )\\r"

	set regexSearch_EscapeStringWARN to "SQL_EscapeString *\\( *([^\\)]+) *\\)"

	set regexReplace_EscapeStringWARN to "\\1 /* WARNING!! Had SQL_EscapeString probably NO LONGER NEEDED, so DISABLED! */"

	tell application "BBEdit"
		activate

		tell window 1

			replace regexSearch_SQL_Table using regexReplace_SQL_Table options {search mode:grep, starting at top:true}

			replace regexSearch_SQL_Field using regexReplace_SQL_Field options {search mode:grep, starting at top:true}

			replace regexSearch_WhereEqualsClause using regexReplace_WhereEqualsClause options {search mode:grep, starting at top:true}
			replace regexSearch_EscapeStringWARN using regexReplace_EscapeStringWARN options {search mode:grep, starting at top:true}

			try
				(* convert to using List ( ) for whitespace formatting of query: *)
				set stringStartQuery to "; sqlQuery = "
				set stringEndQuery to "^([\\t]+); sqlResult = "
				set posQueryStart to characterOffset of found object of (find stringStartQuery)
				set posQueryEnd to (characterOffset of found object of (find stringEndQuery options {search mode:grep})) - 1
				select (characters posQueryStart through posQueryEnd)

				replace "\"SELECT" using "List ( \\r\\t\\t  \"SELECT" searching in selection options {search mode:grep}
				replace "^([\\t]+)& " using "\\t\\t; " searching in selection options {search mode:grep}

				set character posQueryEnd to return & tab & tab & ")" & (contents of character posQueryEnd)

			end try

		end tell

	end tell

end BBEdit_upgrade_SQL_Query_to_newer_format

--------------------
-- END OF CODE
--------------------

-- BBEdit_upgrade_SQL_Query_to_newer_format({})
-- Dan Shockley, NYHTC
-- BBEdit - upgrade SQL Query to newer format

(*
HISTORY:
	1.1 - 2017-12-11 ( dshockley ): disable the usually no-longer-needed SQL_EscapeString, but WARN and comment, since it might sitll be needed when using with something OTHER THAN SQL_Where criteria.
	1.0 - 2017-09-15 ( dshockley ): first created.
*)

on run
	BBEdit_upgrade_SQL_Query_to_newer_format({})
end run

--------------------
-- START OF CODE
--------------------

on BBEdit_upgrade_SQL_Query_to_newer_format({})

	set regexSearch_SQL_Table to "Quote *\\( *TableNameOfField *\\( *([^\\)]+) *\\) *\\)"
	set regexReplace_SQL_Table to "SQL_Table ( \\1 )"

	set regexSearch_SQL_Field to "Quote *\\( ?FieldNameShort *\\( *([^\\)]+) *\\) *\\)"
	set regexReplace_SQL_Field to "SQL_Field ( \\1 )"

	set regexSearch_WhereEqualsClause to "^([\\t ]*)& *SQL_Field *\\( *([^\\)]+) *\\)
[\\t ]*& \" *= *\"
[\\t ]*& ([^\\r]+)\\r"

	set regexReplace_WhereEqualsClause to "\\1\\& SQL_Where ( \\2 ; \"=\" ; \\3 )\\r"

	set regexSearch_EscapeStringWARN to "SQL_EscapeString *\\( *([^\\)]+) *\\)"

	set regexReplace_EscapeStringWARN to "\\1 /* WARNING!! Had SQL_EscapeString probably NO LONGER NEEDED, so DISABLED! */"

	tell application "BBEdit"
		activate

		tell window 1

			replace regexSearch_SQL_Table using regexReplace_SQL_Table options {search mode:grep, starting at top:true}

			replace regexSearch_SQL_Field using regexReplace_SQL_Field options {search mode:grep, starting at top:true}

			replace regexSearch_WhereEqualsClause using regexReplace_WhereEqualsClause options {search mode:grep, starting at top:true}
			replace regexSearch_EscapeStringWARN using regexReplace_EscapeStringWARN options {search mode:grep, starting at top:true}

		end tell

	end tell
end BBEdit_upgrade_SQL_Query_to_newer_format

--------------------
-- END OF CODE
--------------------


fixmoveformon

fixmoveformon

property USE_SIDEBAR : false
property DEF_ALL : false
property DEF_DEBUG_LEVEL : 0

on moveForMon(pars)
	-- set default variables
	set all to all of (pars & {all:DEF_ALL})
	set debug_level to debug_level of (pars & {debug_level:DEF_DEBUG_LEVEL})

	-- 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

	if USE_SIDEBAR then
		-- 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 m_width to 160
		set ledge to -1 * m_width
		set ledgeSFCoffset to 20

		-- y positions
		set y_sfcCEST to 30
		set sfc_height to 100
		set y_sfcJST to y_sfcCEST + sfc_height
		set y_gtCal to y_sfcJST + sfc_height + 5
		set gtCal_height to 115
		set y_gtGcal to y_gtCal + gtCal_height
		set gtGcal_height to 175
		set y_gtTask to y_gtGcal + gtGcal_height
		set gtTask_height to 85
		set y_gtPs to y_gtTask + gtTask_height
		set gtPs_height to 75
		set y_XRG to y_gtPs + gtPs_height
		set XRG_height to 400
	end if

	-- 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
	set scriptPath to ((path to me as text) & "::")
	set windowSizeScpt to scriptPath & "windowSize.scpt"
	set ws to load script file windowSizeScpt
	set getFrameScpt to scriptPath & "getFrame.scpt"
	set gf to load script file getFrameScpt

	-- main screen
	set vframes to gf's getAllVisibleFrames()
	-- dpoxY needs to be enough bigger than menubar's (~23) height
	set dPosX to 100
	set dPosY to 100
	set dWidth to gf's getFrameWidth(item 1 of (vframes's main_frames))
	set dHeight to gf's getFrameHeight(item 1 of (vframes's main_frames))

	-- try to get left screen
	set dPosX_L to dPosX
	set dPosY_L to dPosY
	if length of vframes's left_frames > 0 then
		set dPosX_L to (gf's getFrameOriginX(item 1 of (vframes's left_frames))) + 100
		set dPosY_L to (gf's getFrameOriginY(item 1 of (vframes's left_frames))) + 100
	end if

	-- try to get right screen
	set dPosX_R to dPosX + 1
	set dPosY_R to dPosY + 1
	if length of vframes's right_frames > 0 then
		set dPosX_R to (gf's getFrameOriginX(item 1 of (vframes's right_frames))) + 100
		set dPosY_R to (gf's getFrameOriginY(item 1 of (vframes's right_frames))) + 100
	end if

	if USE_SIDEBAR then
		-- move monitoring tools
		if length of vframes's left_frames > 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 {m_width, sfc_height}
						set position to {ledge + ledgeSFCoffset, y_sfcCEST}
					end tell
					tell window w_sfcJST
						set size to {m_width, sfc_height}
						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 {m_width, XRG_height}
						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
					if name is s_gtCal then
						set x to ledge
						set y to y_gtCal
					else if name is s_gtGcal then
						set x to ledge
						set y to y_gtGcal
					else if name is s_gtTask then
						set x to ledge
						set y to y_gtTask
					else if name is s_gtPs then
						set x to ledge
						set y to y_gtPs
					end if
				end tell
			end repeat
		end tell
	end if

	-- 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
									ws'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
									ws'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
									ws'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
									ws'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
									ws'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
									ws'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 USE_SIDEBAR : false
property DEF_ALL : false
property DEF_DEBUG_LEVEL : 0

on moveForMon(pars)
	-- set default variables
	set all to all of (pars & {all:DEF_ALL})
	set debug_level to debug_level of (pars & {debug_level:DEF_DEBUG_LEVEL})

	-- 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

	if USE_SIDEBAR then
		-- 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 m_width to 160
		set ledge to -1 * m_width
		set ledgeSFCoffset to 20

		-- y positions
		set y_sfcCEST to 30
		set sfc_height to 100
		set y_sfcJST to y_sfcCEST + sfc_height
		set y_gtCal to y_sfcJST + sfc_height + 5
		set gtCal_height to 115
		set y_gtGcal to y_gtCal + gtCal_height
		set gtGcal_height to 175
		set y_gtTask to y_gtGcal + gtGcal_height
		set gtTask_height to 85
		set y_gtPs to y_gtTask + gtTask_height
		set gtPs_height to 75
		set y_XRG to y_gtPs + gtPs_height
		set XRG_height to 400
	end if

	-- 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
	set scriptPath to ((path to me as text) & "::")
	set windowSizeScpt to scriptPath & "windowSize.scpt"
	set ws to load script file windowSizeScpt
	set getFrameScpt to scriptPath & "getFrame.scpt"
	set gf to load script file getFrameScpt

	-- main screen
	set vframes to gf's getAllVisibleFrames()
	-- dpoxY needs to be enough bigger than menubar's (~23) height
	set dPosX to 100
	set dPosY to 100
	set dWidth to gf's getFrameWidth(item 1 of (vframes's main_frames))
	set dHeight to gf's getFrameHeight(item 1 of (vframes's main_frames))

	-- try to get left screen
	set dPosX_L to dPosX
	set dPosY_L to dPosY
	if length of vframes's left_frames > 0 then
		set dPosX_L to (gf's getFrameOriginX(item 1 of (vframes's left_frames))) + 100
		set dPosY_L to (gf's getFrameOriginY(item 1 of (vframes's left_frames))) + 100
	end if

	-- try to get right screen
	set dPosX_R to dPosX + 1
	set dPosY_R to dPosY + 1
	if length of vframes's right_frames > 0 then
		set dPosX_R to (gf's getFrameOriginX(item 1 of (vframes's right_frames))) + 100
		set dPosY_R to (gf's getFrameOriginY(item 1 of (vframes's right_frames))) + 100
	end if

	if USE_SIDEBAR then
		-- move monitoring tools
		if length of vframes's left_frames > 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 {m_width, sfc_height}
						set position to {ledge + ledgeSFCoffset, y_sfcCEST}
					end tell
					tell window w_sfcJST
						set size to {m_width, sfc_height}
						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 {m_width, XRG_height}
						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.app" -- can not use appName (variable), which shows error at id?
			--geeklets
			repeat with g in every «class gLet»
				tell g
					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
	end if

	-- 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
									ws'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
									ws'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
									ws'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
									ws'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
									ws'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
									ws'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


Working applescript to record with QT

Working applescript to record with QT

FasdUAS 1.101.10
l
i
I
.aevtoappnull****
o0argv
OG
kF

r

I
.MVWRnavrnullnull
o&0newmovierecordingnewMovieRecording
l
OF
kE
I
.MVWRstarnulldocu
I
.sysodelanullnmbr
n
4

cobj
m
o0argv
I$
.MVWRpausnulldocu
I%9!"
.coresavenullobj
!o%&&0newmovierecordingnewMovieRecording"#

kfil
#4'5$

psxf
$l)4%
%b)4&'
&b)2()
(n)-*+
*4*-,

cobj
,m+,
+o)*0argv
)n-1-.
-4.1/

cobj
/m/0
.o-.0argv
'm230011.mov 23
2I:?
.MVWRstopnulldocu34
4I@E5
.coreclosnullobj
5o@A&0newmovierecordingnewMovieRecording
o
&0newmovierecordingnewMovieRecording
	m66mgvralisvMacintosh HDA'H+IQuickTime Player.app-sҟlE	 ApplicationsAmҟI/Macintosh HD:Applications:QuickTime Player.app*QuickTime Player.appMacintosh HD!Applications/QuickTime Player.app/7897
.aevtoappnull****&0newmovierecordingnewMovieRecording8:;
.aevtoappnull****0argv:0argv;
60
.MVWRnavrnullnull&0newmovierecordingnewMovieRecording
.MVWRstarnulldocu

cobj
.sysodelanullnmbr
.MVWRpausnulldocu

kfil

psxf
.coresavenullobj
.MVWRstopnulldocu
.coreclosnullobj HD*jEO7*jOm/jO*jO*k/l/%%/l
O*jOjUU9<<6=

docu=>>Movie Recordingascrޭ

FasdUAS 1.101.10
l
i
I
.aevtoappnull****
o0argv
kT

	r

G

4

cobj
m
o	0argv
o0savepathsavePath

r
n
4

cobj
m
o0argv
o0	moviename	movieName
r
n
4

cobj
m
o0argv
o0rectimerecTime
l
 OT!"
!k S##$%
$r '&'
&I %
.MVWRnavrnullnull
'o&0newmovierecordingnewMovieRecording%()
(l(()*
*O(S+,
+k,R--./
.I,1
.MVWRstarnulldocu/01
0I272
.sysodelanullnmbr
2o230rectimerecTime134
3I8=
.MVWRpausnulldocu456
5I>L78
.coresavenullobj
7o>?&0newmovierecordingnewMovieRecording89

kfil
94@H:

psxf
:lBG;
;bBG<=
<bBE>?
>oBC0savepathsavePath
?oCD0	moviename	movieName
=mEF@@AA.mov6B
BIMRC
.coreclosnullobj
CoMN&0newmovierecordingnewMovieRecording
,o()&0newmovierecordingnewMovieRecording
"mDDmgvralisvMacintosh HDA'H+IQuickTime Player.app-sҟlE	 ApplicationsAmҟI/Macintosh HD:Applications:QuickTime Player.app*QuickTime Player.appMacintosh HD!Applications/QuickTime Player.app/EFE
.aevtoappnull****FGH
.aevtoappnull****0argvG0argvHD@

cobj

bool0savepathsavePath0	moviename	movieName0rectimerecTime
.MVWRnavrnullnull&0newmovierecordingnewMovieRecording
.MVWRstarnulldocu
.sysodelanullnmbr
.MVWRpausnulldocu

kfil

psxf
.coresavenullobj
.coreclosnullobj U*k/E
&EOl/EOm/EO5*jEO(*jOj	O*j
O*%%/lOjUUascrޭ


CS4 -> CC 2019

CS4 -> CC 2019

do shell script "/usr/local/bin/python3 /Volumes/Server/Production\\ Resources/Scripts/ms-weather/weather.py"
tell application "Adobe InDesign CC 2019" to activate

do shell script "/usr/local/bin/python3 /Volumes/Server/Production\\ Resources/Scripts/ms-weather/weather.py"
tell application "Adobe InDesign CS4" to activate


Delete listeningtospotify.scpt

Delete listeningtospotify.scpt

FasdUAS 1.101.10
k
l
r
m
	o
0	countthis

l
V

k
O
k
r
l
[
o
0	countthis
m
o
0	countthis
Z
=
1

pPlS
 m
ePlSkPSP
k !!"#
"r '$%
$n %&'
&1#%

pnam
'1 #

pTrk
%o0thesongtheSong#()
(r(/*+
*n(-,-
,1+-

pAlb
-1(+

pTrk
+o0thealbumtheAlbum)./
.r0701
0n0523
2135

pArt
3103

pTrk
1o0	theartist	theArtist/45
4r8=67
618;

pTrk
7o0	thistrack	thisTrack589
8r>E:;
:l>C<
C
.misccurdldt null
;o0thedatetheDate9=>
=ZF?@
?>FMAB
AnFICD
C1GI

pcnt
DoFG0	theartist	theArtist
BmILEEFF
@lPGHI
GkPJJKL
KlPPMNM/)modify with your server information belowNOORmodify with your server information belowLPQ
PrP_RS
RIP[TU
.rdwropenshorfile
TmPSVVWW4/Your/Server/listening.phpUX

perm
XmVW
boovtrue
So0myfilemyFileQYZ
YI`k[\
.rdwrseofnull****
[o`c0myfilemyFile\]

set2
]mfgZ^_
^Il`a
.rdwrwritnull****
`llb
bclcd
cJleefg
fmlohhiijListening To:
gjk
joop0thesongtheSongklm
lmpsnnoo by mpq
post0	theartist	theArtistqrs
rmtwttuuB
svw
vowx0thedatetheDatewx
xmx{yyzz
dm

TEXTa{

refn
{o0myfilemyFile_|}
|I~
.rdwrclosnull****
~o0myfilemyFile}
l
r
m>http://Your/Server/transmit.php
o 0alerturlstringAlertURLString"modify with your server info8modify with your server info
r
I
.sysoexecTEXTTEXT
b
b
mcurl '
o 0alerturlstringAlertURLString
m'
o0
curloutput
curlOutputH& don't update this if it is an adI@don't update this if it is an ad>
l
delay 3delay 3
l
end repeatend repeat
m@alis>SteshaEH+B[Spotify.apphgo	 ApplicationsE6B[ Stesha:Applications:Spotify.appSpotify.appSteshaApplications/Spotify.app/
l
l
I
.sysodelanullnmbr
m5/run this every 30 seconds; can change as needed^run this every 30 seconds; can change as needed
=

n
1

prun
m	@alis>SteshaEH+B[Spotify.apphgo	 ApplicationsE6B[ Stesha:Applications:Spotify.appSpotify.appSteshaApplications/Spotify.app/
m
boovtrue
l
l
.aevtoappnull****
.aevtoappnull****
k
(EVhnty
0	countthis

prun

pPlS
ePlSkPSP

pTrk

pnam0thesongtheSong

pAlb0thealbumtheAlbum

pArt0	theartist	theArtist0	thistrack	thisTrack
.misccurdldt null0thedatetheDate

pcnt

perm
.rdwropenshorfile0myfilemyFile

set2
.rdwrseofnull****

TEXT

refn
.rdwrwritnull****
.rdwrclosnull**** 0alerturlstringAlertURLString
.sysoexecTEXTTEXT0
curloutput
curlOutput
.sysodelanullnmbrjEOh,ekEO*,*,,EO*,,EO*,,EO*,EO*j
EO,afaaelE`O_ajlOaaaaava&a_lO_jOa E`!Oa"_!%a#%j$E`%YhOPYhUOa&j'[OYAascrޭ


Automatically select current version of a model (xmod comment has to be set on xcdatamodeld group)

property kExplicitlyProcessedOptions : {"--human-dir ", "--machine-dir ", "--output-dir ", "--log-command"}

tell application "Xcode"
	if not (exists active project document) then
		error "No active project. Please open an Xcode project and re-run the script."
	try
		my updateProjectXmod(project of active project document)
	on error errMsg
		my logger("Xmod.scpt exception: " & errMsg)
	end try
end tell

on updateProjectXmod(_project)
	tell application "Xcode"
		-- Iterate over every .xcdatamodel in the project.
		set modelList to every file reference of _project whose file kind is "wrapper.xcdatamodel" and comments contains "xmod"
		repeat with modelItr in modelList
			my updateModel(_project, modelItr, comments of modelItr)
		end repeat
		-- Iterate over every .xcdatamodeld (notice the 'd') in the project.
		set modeldList to every group of _project whose name contains ".xcdatamodeld" and comments contains "xmod"
		repeat with modeldIt in modeldList
			-- Find the 'active' model version
			set currentVersionFile to full path of modeldIt & "/.xccurrentversion"
			set activeModelVersionFilename to do shell script "/usr/libexec/PlistBuddy -c 'print _XCCurrentVersionName' " & currentVersionFile
			set activeModelVersion to full path of modeldIt & "/" & activeModelVersionFilename
			set modelItr to item 1 of (every file reference of modeldIt whose name is activeModelVersionFilename)
			-- Then update it
			my updateModel(_project, modelItr, comments of modeldIt)
		end repeat
	end tell
end updateProjectXmod

on updateModel(_project, modelItr, theComments)
	tell application "Xcode"

				set modelInfo to my getModelInfo(full path of modelItr, theComments)
				set humanGroupRef to null
				set machineGroupRef to null

				-- Figure out the model's parent group.
				-- Unversioned models are simple files so their group is the answer.
				-- Version models are bundles, which are represented as pseudo-groups in Xcode. You can't ask a pseudo-group for its parent group,
				-- so we discover it by querying project-wide all groups that contain the pseudo-group and using the first result.
				set modelItemRef to item 1 of (every item reference of _project whose full path is (full path of modelItr))
				set modelGroupRef to group of modelItemRef
				if isBundle of modelInfo then
					set modelGroupRef to item 1 of (every group of _project whose groups contains modelGroupRef)
				end if

				-- look for a group in the project that has the full path of the human manageable files
				set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
				-- if we don't find one, create it in the same group as the model file
				if (count of groupRefs) = 0 then
					tell modelGroupRef
						-- if we have different human and machine paths, then append '_human' to the model name for the group name
						if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo & "_human")}
						else
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo)}
						end if
						set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
					end tell
				end if
				set humanGroupRef to item 1 of groupRefs

				-- if we have different human and machine paths, then look for a group for the machine files
				if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
					set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					-- if we don't find one, create it in the same group as the model file... named with '_machine' appended to the model name
					if (count of groupRefs) = 0 then
						tell modelGroupRef
							make new group with properties {full path:(machineDirPath of modelInfo), name:(name of modelInfo & "_machine")}
						end tell
						set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					end if
					set machineGroupRef to item 1 of groupRefs
				end if

				-- Create the do shell script string and append any custom per model options to it, skipping the ones we've already parsed out
				set logCommand to false
				set theScript to "/usr/bin/mogenerator --model '" & full path of modelItr & "' --human-dir '" & (humanDirPath of modelInfo) & "' --machine-dir '" & (machineDirPath of modelInfo) & "'"
				set theParagraphs to every paragraph of theComments
				repeat with theParagraph in theParagraphs
					if theParagraph starts with "--" then
						set isExplicitlyProcessedOption to false
						repeat with explicitlyProcessedOption in kExplicitlyProcessedOptions
							if theParagraph starts with explicitlyProcessedOption then set isExplicitlyProcessedOption to true
						end repeat
						if not isExplicitlyProcessedOption then
							set theScript to theScript & " " & the text of theParagraph
						end if
						if theParagraph starts with "--log-command" then
							set logCommand to true
						end if
					end if
				end repeat

				--	Meat.
				if logCommand then
					my logger(theScript)
				end if
				do shell script theScript

				my addFilesFromPathToGroup(_project, modelItr, humanGroupRef)
				if machineGroupRef is not null then
					my addFilesFromPathToGroup(_project, modelItr, machineGroupRef)
				end if
	end tell
end updateModel

on everyTargetWithBuildFilePath(_project, _buildFilePath)
	set theResult to {}
	tell application "Xcode"
		repeat with targetItr in (every target of _project)
			repeat with buildFileItr in build files of targetItr
				if full path of file reference of buildFileItr is _buildFilePath then set theResult to theResult & {(targetItr as anything)}
			end repeat
		end repeat
	end tell
	return theResult
end everyTargetWithBuildFilePath

on getModelInfo(modelFileUnixPath, theComments)
	set modelFilePosixRef to POSIX file modelFileUnixPath
	set modelFileAlias to modelFilePosixRef as alias
	set theOutputDir to ""
	set theHumanDir to ""
	set theMachineDir to ""

	-- check for any directory path options specified in the commments
	set theParagraphs to every paragraph of theComments
	repeat with theParagraph in theParagraphs
		set paragraphLength to (length of theParagraph)
		if (offset of "--human-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--human-dir ") + 1
			if remainderOffset > paragraphLength then
				set theHumanDir to ""
			else
				set theHumanDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--machine-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--machine-dir ") + 1
			if remainderOffset > paragraphLength then
				set theMachineDir to ""
			else
				set theMachineDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--output-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--output-dir ") + 1
			if remainderOffset > paragraphLength then
				set theOutputDir to ""
			else
				set theOutputDir to text remainderOffset thru -1 of theParagraph
			end if
		end if
	end repeat

	-- remove any leading/trailing spaces or tabs from the paths
	if (length of theHumanDir) > 0 then
		repeat while character 1 of theHumanDir = tab or character 1 of theHumanDir = space
			set theHumanDir to text 2 thru -1 of theHumanDir
		end repeat
		repeat while last character of theHumanDir = tab or last character of theHumanDir = space
			set theHumanDir to text 1 thru -2 of theHumanDir
		end repeat
	end if

	if (length of theMachineDir) > 0 then
		repeat while character 1 of theMachineDir = tab or character 1 of theMachineDir = space
			set theMachineDir to text 2 thru -1 of theMachineDir
		end repeat
		repeat while last character of theMachineDir = tab or last character of theMachineDir = space
			set theMachineDir to text 1 thru -2 of theMachineDir
		end repeat
	end if

	if (length of theOutputDir) > 0 then
		repeat while character 1 of theOutputDir = tab or character 1 of theOutputDir = space
			set theOutputDir to text 2 thru -1 of theOutputDir
		end repeat
		repeat while last character of theOutputDir = tab or last character of theOutputDir = space
			set theOutputDir to text 1 thru -2 of theOutputDir
		end repeat
	end if

	-- get actual the model info and modify value for theOutputDir if necessary
	tell application "Finder"
		set modelFileFolder to folder of modelFileAlias

		set isModelBundle to name of modelFileFolder ends with ".xcdatamodeld"
		if isModelBundle then
			set modelFileAlias to (folder of modelFileAlias) as alias -- it's a bundle, go up one folder
			set modelFileFolder to folder of modelFileAlias
		end if

		set modelFileName to name of modelFileAlias
		if isModelBundle then
			set extensionLength to length of ".xcdatamodeld"
		else
			set extensionLength to length of ".xcdatamodel"
		end if

		set modelName to text 1 thru -(extensionLength + 1) of modelFileName -- pull off the extension

		-- if we didn't find any directory specifiers in the comments, then make theOutputDir the folder containg the model file
		if ((length of theOutputDir) = 0) and ((length of theHumanDir) = 0) and ((length of theMachineDir) = 0) then
			if not (exists folder modelName of modelFileFolder) then
				make folder at modelFileFolder with properties {name:modelName}
			set modelSrcFolder to folder modelName of modelFileFolder
			set theOutputDir to text 1 thru -2 of (POSIX path of (modelSrcFolder as alias))
			-- otherwise, if theOutputDir isn't a full path itself already, set theOutputDir to a full path relative to the model file
		else if theOutputDir does not start with "/" then
			set modelFolderPath to text 1 thru -2 of (POSIX path of (modelFileFolder as alias))
			if (length of theOutputDir) = 0 then
				set theOutputDir to modelFolderPath
			else
				copy modelFolderPath & "/" & theOutputDir to theOutputDir
			end if
		end if

	end tell

	-- if theHumanDir is empty, use theOutputDir value instead, if theHumanDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theHumanDir) = 0 then
		set theHumanDir to theOutputDir
	else if theHumanDir does not start with "/" then
		copy theOutputDir & "/" & theHumanDir to theHumanDir
	end if

	-- if theMachineDir is empty, use theOutputDir value instead, if theMachineDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theMachineDir) = 0 then
		set theMachineDir to theOutputDir
	else if theMachineDir does not start with "/" then
		copy theOutputDir & "/" & theMachineDir to theMachineDir
	end if

	-- ensure the directories exist
	do shell script "mkdir -p '" & theHumanDir & "'"
	do shell script "mkdir -p '" & theMachineDir & "'"

	-- the following should resolve any symlinks, '..', or '~' in the paths
	tell application "System Events"
		set dirAlias to POSIX file theHumanDir as alias
		set theHumanDir to (POSIX path of (dirAlias as alias))
		set dirAlias to POSIX file theMachineDir as alias
		set theMachineDir to (POSIX path of (dirAlias as alias))
	end tell

	return {name:modelName, isBundle:isModelBundle, machineDirPath:theMachineDir, humanDirPath:theHumanDir}

end getModelInfo

on logger(msg)
	do shell script "logger '" & msg & "'"
end logger

on addFilesFromPathToGroup(_project, modelItr, groupRef)
	tell application "Xcode"
		-- get the full path of the directory that the groupRef represents
		set groupPath to full path of groupRef

		--	Build a list of source files in the group's directory
		tell application "System Events"
			set modelSrcDirAlias to POSIX file groupPath as alias
			set fileList to (every file of modelSrcDirAlias whose (name ends with ".m" or name ends with ".mm" or name ends with ".h"))
			set pathList to {}
			repeat with fileItem in fileList
				set pathList to pathList & POSIX path of fileItem
			end repeat
		end tell

		--	Add the source files to the group and the model's targets, but only if they don't exist already
		set targetList to null
		repeat with pathItr in pathList
			tell groupRef
				set fileRefs to (every file reference of _project whose full path is pathItr)
				if (count of fileRefs) = 0 then
					set modelSrcFileRef to make new file reference with properties {full path:pathItr, name:name of (info for POSIX file pathItr)}
					if targetList is null then
						set targetList to my everyTargetWithBuildFilePath(_project, full path of modelItr)
					end if
					repeat with targetIndex from 1 to (count of targetList)
						set targetItr to item targetIndex of targetList
						add modelSrcFileRef to targetItr
					end repeat
				end if
			end tell
		end repeat
	end tell
end addFilesFromPathToGroup

property kExplicitlyProcessedOptions : {"--human-dir ", "--machine-dir ", "--output-dir ", "--log-command"}

tell application "Xcode"
	if not (exists active project document) then
		error "No active project. Please open an Xcode project and re-run the script."
	try
		my updateProjectXmod(project of active project document)
	on error errMsg
		my logger("Xmod.scpt exception: " & errMsg)
	end try
end tell

on updateProjectXmod(_project)
	tell application "Xcode"
		-- Iterate over every .xcdatamodel in the project.
		set modelList to every file reference of _project whose file kind is "wrapper.xcdatamodel" and comments contains "xmod"
		repeat with modelItr in modelList
			my updateModel(_project, modelItr, comments of modelItr)
		end repeat
	end tell
end updateProjectXmod

on updateModel(_project, modelItr, theComments)
	tell application "Xcode"

				set modelInfo to my getModelInfo(full path of modelItr, theComments)
				set humanGroupRef to null
				set machineGroupRef to null

				-- Figure out the model's parent group.
				-- Unversioned models are simple files so their group is the answer.
				-- Version models are bundles, which are represented as pseudo-groups in Xcode. You can't ask a pseudo-group for its parent group,
				-- so we discover it by querying project-wide all groups that contain the pseudo-group and using the first result.
				set modelItemRef to item 1 of (every item reference of _project whose full path is (full path of modelItr))
				set modelGroupRef to group of modelItemRef
				if isBundle of modelInfo then
					set modelGroupRef to item 1 of (every group of _project whose groups contains modelGroupRef)
				end if

				-- look for a group in the project that has the full path of the human manageable files
				set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
				-- if we don't find one, create it in the same group as the model file
				if (count of groupRefs) = 0 then
					tell modelGroupRef
						-- if we have different human and machine paths, then append '_human' to the model name for the group name
						if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo & "_human")}
						else
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo)}
						end if
						set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
					end tell
				end if
				set humanGroupRef to item 1 of groupRefs

				-- if we have different human and machine paths, then look for a group for the machine files
				if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
					set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					-- if we don't find one, create it in the same group as the model file... named with '_machine' appended to the model name
					if (count of groupRefs) = 0 then
						tell modelGroupRef
							make new group with properties {full path:(machineDirPath of modelInfo), name:(name of modelInfo & "_machine")}
						end tell
						set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					end if
					set machineGroupRef to item 1 of groupRefs
				end if

				-- Create the do shell script string and append any custom per model options to it, skipping the ones we've already parsed out
				set logCommand to false
				set theScript to "/usr/bin/mogenerator --model '" & full path of modelItr & "' --human-dir '" & (humanDirPath of modelInfo) & "' --machine-dir '" & (machineDirPath of modelInfo) & "'"
				set theParagraphs to every paragraph of theComments
				repeat with theParagraph in theParagraphs
					if theParagraph starts with "--" then
						set isExplicitlyProcessedOption to false
						repeat with explicitlyProcessedOption in kExplicitlyProcessedOptions
							if theParagraph starts with explicitlyProcessedOption then set isExplicitlyProcessedOption to true
						end repeat
						if not isExplicitlyProcessedOption then
							set theScript to theScript & " " & the text of theParagraph
						end if
						if theParagraph starts with "--log-command" then
							set logCommand to true
						end if
					end if
				end repeat

				--	Meat.
				if logCommand then
					my logger(theScript)
				end if
				do shell script theScript

				my addFilesFromPathToGroup(_project, modelItr, humanGroupRef)
				if machineGroupRef is not null then
					my addFilesFromPathToGroup(_project, modelItr, machineGroupRef)
				end if
	end tell
end updateModel

on everyTargetWithBuildFilePath(_project, _buildFilePath)
	set theResult to {}
	tell application "Xcode"
		repeat with targetItr in (every target of _project)
			repeat with buildFileItr in build files of targetItr
				if full path of file reference of buildFileItr is _buildFilePath then set theResult to theResult & {(targetItr as anything)}
			end repeat
		end repeat
	end tell
	return theResult
end everyTargetWithBuildFilePath

on getModelInfo(modelFileUnixPath, theComments)
	set modelFilePosixRef to POSIX file modelFileUnixPath
	set modelFileAlias to modelFilePosixRef as alias
	set theOutputDir to ""
	set theHumanDir to ""
	set theMachineDir to ""

	-- check for any directory path options specified in the commments
	set theParagraphs to every paragraph of theComments
	repeat with theParagraph in theParagraphs
		set paragraphLength to (length of theParagraph)
		if (offset of "--human-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--human-dir ") + 1
			if remainderOffset > paragraphLength then
				set theHumanDir to ""
			else
				set theHumanDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--machine-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--machine-dir ") + 1
			if remainderOffset > paragraphLength then
				set theMachineDir to ""
			else
				set theMachineDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--output-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--output-dir ") + 1
			if remainderOffset > paragraphLength then
				set theOutputDir to ""
			else
				set theOutputDir to text remainderOffset thru -1 of theParagraph
			end if
		end if
	end repeat

	-- remove any leading/trailing spaces or tabs from the paths
	if (length of theHumanDir) > 0 then
		repeat while character 1 of theHumanDir = tab or character 1 of theHumanDir = space
			set theHumanDir to text 2 thru -1 of theHumanDir
		end repeat
		repeat while last character of theHumanDir = tab or last character of theHumanDir = space
			set theHumanDir to text 1 thru -2 of theHumanDir
		end repeat
	end if

	if (length of theMachineDir) > 0 then
		repeat while character 1 of theMachineDir = tab or character 1 of theMachineDir = space
			set theMachineDir to text 2 thru -1 of theMachineDir
		end repeat
		repeat while last character of theMachineDir = tab or last character of theMachineDir = space
			set theMachineDir to text 1 thru -2 of theMachineDir
		end repeat
	end if

	if (length of theOutputDir) > 0 then
		repeat while character 1 of theOutputDir = tab or character 1 of theOutputDir = space
			set theOutputDir to text 2 thru -1 of theOutputDir
		end repeat
		repeat while last character of theOutputDir = tab or last character of theOutputDir = space
			set theOutputDir to text 1 thru -2 of theOutputDir
		end repeat
	end if

	-- get actual the model info and modify value for theOutputDir if necessary
	tell application "Finder"
		set modelFileFolder to folder of modelFileAlias

		set isModelBundle to name of modelFileFolder ends with ".xcdatamodeld"
		if isModelBundle then
			set modelFileAlias to (folder of modelFileAlias) as alias -- it's a bundle, go up one folder
			set modelFileFolder to folder of modelFileAlias
		end if

		set modelFileName to name of modelFileAlias
		if isModelBundle then
			set extensionLength to length of ".xcdatamodeld"
		else
			set extensionLength to length of ".xcdatamodel"
		end if

		set modelName to text 1 thru -(extensionLength + 1) of modelFileName -- pull off the extension

		-- if we didn't find any directory specifiers in the comments, then make theOutputDir the folder containg the model file
		if ((length of theOutputDir) = 0) and ((length of theHumanDir) = 0) and ((length of theMachineDir) = 0) then
			if not (exists folder modelName of modelFileFolder) then
				make folder at modelFileFolder with properties {name:modelName}
			set modelSrcFolder to folder modelName of modelFileFolder
			set theOutputDir to text 1 thru -2 of (POSIX path of (modelSrcFolder as alias))
			-- otherwise, if theOutputDir isn't a full path itself already, set theOutputDir to a full path relative to the model file
		else if theOutputDir does not start with "/" then
			set modelFolderPath to text 1 thru -2 of (POSIX path of (modelFileFolder as alias))
			if (length of theOutputDir) = 0 then
				set theOutputDir to modelFolderPath
			else
				copy modelFolderPath & "/" & theOutputDir to theOutputDir
			end if
		end if

	end tell

	-- if theHumanDir is empty, use theOutputDir value instead, if theHumanDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theHumanDir) = 0 then
		set theHumanDir to theOutputDir
	else if theHumanDir does not start with "/" then
		copy theOutputDir & "/" & theHumanDir to theHumanDir
	end if

	-- if theMachineDir is empty, use theOutputDir value instead, if theMachineDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theMachineDir) = 0 then
		set theMachineDir to theOutputDir
	else if theMachineDir does not start with "/" then
		copy theOutputDir & "/" & theMachineDir to theMachineDir
	end if

	-- ensure the directories exist
	do shell script "mkdir -p '" & theHumanDir & "'"
	do shell script "mkdir -p '" & theMachineDir & "'"

	-- the following should resolve any symlinks, '..', or '~' in the paths
	tell application "System Events"
		set dirAlias to POSIX file theHumanDir as alias
		set theHumanDir to (POSIX path of (dirAlias as alias))
		set dirAlias to POSIX file theMachineDir as alias
		set theMachineDir to (POSIX path of (dirAlias as alias))
	end tell

	return {name:modelName, isBundle:isModelBundle, machineDirPath:theMachineDir, humanDirPath:theHumanDir}

end getModelInfo

on logger(msg)
	do shell script "logger '" & msg & "'"
end logger

on addFilesFromPathToGroup(_project, modelItr, groupRef)
	tell application "Xcode"
		-- get the full path of the directory that the groupRef represents
		set groupPath to full path of groupRef

		--	Build a list of source files in the group's directory
		tell application "System Events"
			set modelSrcDirAlias to POSIX file groupPath as alias
			set fileList to (every file of modelSrcDirAlias whose (name ends with ".m" or name ends with ".mm" or name ends with ".h"))
			set pathList to {}
			repeat with fileItem in fileList
				set pathList to pathList & POSIX path of fileItem
			end repeat
		end tell

		--	Add the source files to the group and the model's targets, but only if they don't exist already
		set targetList to null
		repeat with pathItr in pathList
			tell groupRef
				set fileRefs to (every file reference of _project whose full path is pathItr)
				if (count of fileRefs) = 0 then
					set modelSrcFileRef to make new file reference with properties {full path:pathItr, name:name of (info for POSIX file pathItr)}
					if targetList is null then
						set targetList to my everyTargetWithBuildFilePath(_project, full path of modelItr)
					end if
					repeat with targetIndex from 1 to (count of targetList)
						set targetItr to item targetIndex of targetList
						add modelSrcFileRef to targetItr
					end repeat
				end if
			end tell
		end repeat
	end tell
end addFilesFromPathToGroup


Changed Xmod.applescript to better support --machine-dir, --human-dir and --output-dir comments... directories can be specified as either full or relative paths (relative to model file). Xcode group and file references are no longer deleted/re-added with every save. New files are added automatically. This allows group references to be moved or contain files that are not auto generated.

tell application "Xcode"
	if not (exists active project document) then
		error "No active project. Please open an Xcode project and re-run the script."
	try
		my updateProjectXmod(project of active project document)
	on error errMsg
		my logger("Xmod.scpt exception: " & errMsg)
	end try
end tell

on updateProjectXmod(_project)
	tell application "Xcode"
		-- Iterate over every .xcdatamodel in the project.
		set modelList to every file reference of _project whose file kind is "wrapper.xcdatamodel"
		repeat with modelItr in modelList
			set theComments to the comments of modelItr
			if theComments contains "xmod" then

				set modelInfo to my getModelInfo(full path of modelItr, theComments)
				set humanGroupRef to null
				set machineGroupRef to null

				-- Figure out the model's parent group.
				-- Unversioned models are simple files so their group is the answer.
				-- Version models are bundles, which are represented as pseudo-groups in Xcode. You can't ask a pseudo-group for its parent group,
				-- so we discover it by querying project-wide all groups that contain the pseudo-group and using the first result.
				set modelItemRef to item 1 of (every item reference of _project whose full path is (full path of modelItr))
				set modelGroupRef to group of modelItemRef
				if isBundle of modelInfo then
					set modelGroupRef to item 1 of (every group of _project whose groups contains modelGroupRef)
				end if

				-- look for a group in the project that has the full path of the human manageable files
				set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
				-- if we don't find one, create it in the same group as the model file
				if (count of groupRefs) = 0 then
					tell modelGroupRef
						-- if we have different human and machine paths, then append '_human' to the model name for the group name
						if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo & "_human")}
						else
							make new group with properties {full path:(humanDirPath of modelInfo), name:(name of modelInfo)}
						end if
						set groupRefs to (every group of _project whose full path is (humanDirPath of modelInfo))
					end tell
				end if
				set humanGroupRef to item 1 of groupRefs

				-- if we have different human and machine paths, then look for a group for the machine files
				if (humanDirPath of modelInfo) is not equal to (machineDirPath of modelInfo) then
					set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					-- if we don't find one, create it in the same group as the model file... named with '_machine' appended to the model name
					if (count of groupRefs) = 0 then
						tell modelGroupRef
							make new group with properties {full path:(machineDirPath of modelInfo), name:(name of modelInfo & "_machine")}
						end tell
						set groupRefs to (every group of _project whose full path is (machineDirPath of modelInfo))
					end if
					set machineGroupRef to item 1 of groupRefs
				end if

				-- Create the do shell script string and append any custom per model options to it, skipping the ones we've already parsed out
				set theScript to "/usr/bin/mogenerator --model '" & full path of modelItr & "' --human-dir '" & (humanDirPath of modelInfo) & "' --machine-dir '" & (machineDirPath of modelInfo) & "'"
				set theParagraphs to every paragraph of theComments
				repeat with theParagraph in theParagraphs
					if (length of the characters of theParagraph) is greater than 2 then
						set theToken to the first character of theParagraph & the second character of theParagraph
						if theToken is "--" then
							if ((offset of "--human-dir " in theParagraph) = 0) and ((offset of "--machine-dir " in theParagraph) = 0) and ((offset of "--output-dir " in theParagraph) = 0) then
								set theScript to theScript & " " & the text of theParagraph
							end if
						end if
					end if
				end repeat

				--	Meat.
				do shell script theScript

				my addFilesFromPathToGroup(_project, modelItr, humanGroupRef)
				if machineGroupRef is not null then
					my addFilesFromPathToGroup(_project, modelItr, machineGroupRef)
				end if
			end if
		end repeat
	end tell
end updateProjectXmod

on everyTargetWithBuildFilePath(_project, _buildFilePath)
	set theResult to {}
	tell application "Xcode"
		repeat with targetItr in (every target of _project)
			repeat with buildFileItr in build files of targetItr
				if full path of file reference of buildFileItr is _buildFilePath then set theResult to theResult & {(targetItr as anything)}
			end repeat
		end repeat
	end tell
	return theResult
end everyTargetWithBuildFilePath

on getModelInfo(modelFileUnixPath, theComments)
	set modelFilePosixRef to POSIX file modelFileUnixPath
	set modelFileAlias to modelFilePosixRef as alias
	set theOutputDir to ""
	set theHumanDir to ""
	set theMachineDir to ""

	-- check for any directory path options specified in the commments
	set theParagraphs to every paragraph of theComments
	repeat with theParagraph in theParagraphs
		set paragraphLength to (length of theParagraph)
		if (offset of "--human-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--human-dir ") + 1
			if remainderOffset > paragraphLength then
				set theHumanDir to ""
			else
				set theHumanDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--machine-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--machine-dir ") + 1
			if remainderOffset > paragraphLength then
				set theMachineDir to ""
			else
				set theMachineDir to text remainderOffset thru -1 of theParagraph
			end if
		else if (offset of "--output-dir " in theParagraph) = 1 then
			set remainderOffset to (length of "--output-dir ") + 1
			if remainderOffset > paragraphLength then
				set theOutputDir to ""
			else
				set theOutputDir to text remainderOffset thru -1 of theParagraph
			end if
		end if
	end repeat

	-- remove any leading/trailing spaces or tabs from the paths
	if (length of theHumanDir) > 0 then
		repeat while character 1 of theHumanDir = tab or character 1 of theHumanDir = space
			set theHumanDir to text 2 thru -1 of theHumanDir
		end repeat
		repeat while last character of theHumanDir = tab or last character of theHumanDir = space
			set theHumanDir to text 1 thru -2 of theHumanDir
		end repeat
	end if

	if (length of theMachineDir) > 0 then
		repeat while character 1 of theMachineDir = tab or character 1 of theMachineDir = space
			set theMachineDir to text 2 thru -1 of theMachineDir
		end repeat
		repeat while last character of theMachineDir = tab or last character of theMachineDir = space
			set theMachineDir to text 1 thru -2 of theMachineDir
		end repeat
	end if

	if (length of theOutputDir) > 0 then
		repeat while character 1 of theOutputDir = tab or character 1 of theOutputDir = space
			set theOutputDir to text 2 thru -1 of theOutputDir
		end repeat
		repeat while last character of theOutputDir = tab or last character of theOutputDir = space
			set theOutputDir to text 1 thru -2 of theOutputDir
		end repeat
	end if

	-- get actual the model info and modify value for theOutputDir if necessary
	tell application "Finder"
		set modelFileFolder to folder of modelFileAlias

		set isModelBundle to name of modelFileFolder ends with ".xcdatamodeld"
		if isModelBundle then
			set modelFileAlias to (folder of modelFileAlias) as alias -- it's a bundle, go up one folder
			set modelFileFolder to folder of modelFileAlias
		end if

		set modelFileName to name of modelFileAlias
		if isModelBundle then
			set extensionLength to length of ".xcdatamodeld"
		else
			set extensionLength to length of ".xcdatamodel"
		end if

		set modelName to text 1 thru -(extensionLength + 1) of modelFileName -- pull off the extension

		-- if we didn't find any directory specifiers in the comments, then make theOutputDir the folder containg the model file
		if ((length of theOutputDir) = 0) and ((length of theHumanDir) = 0) and ((length of theMachineDir) = 0) then
			set modelSrcFolder to folder modelName of modelFileFolder
			set theOutputDir to text 1 thru -2 of (POSIX path of (modelSrcFolder as alias))
			-- otherwise, if theOutputDir isn't a full path itself already, set theOutputDir to a full path relative to the model file
		else if theOutputDir does not start with "/" then
			set modelFolderPath to text 1 thru -2 of (POSIX path of (modelFileFolder as alias))
			if (length of theOutputDir) = 0 then
				set theOutputDir to modelFolderPath
			else
				copy modelFolderPath & "/" & theOutputDir to theOutputDir
			end if
		end if

	end tell

	-- if theHumanDir is empty, use theOutputDir value instead, if theHumanDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theHumanDir) = 0 then
		set theHumanDir to theOutputDir
	else if theHumanDir does not start with "/" then
		copy theOutputDir & "/" & theHumanDir to theHumanDir
	end if

	-- if theMachineDir is empty, use theOutputDir value instead, if theMachineDir not empty and it isn't a full path, then treat it as a relative path to theOutputDir
	if (length of theMachineDir) = 0 then
		set theMachineDir to theOutputDir
	else if theMachineDir does not start with "/" then
		copy theOutputDir & "/" & theMachineDir to theMachineDir
	end if

	-- ensure the directories exist
	do shell script "mkdir -p '" & theHumanDir & "'"
	do shell script "mkdir -p '" & theMachineDir & "'"

	-- the following should resolve any symlinks, '..', or '~' in the paths
	tell application "System Events"
		set dirAlias to POSIX file theHumanDir as alias
		set theHumanDir to (POSIX path of (dirAlias as alias))
		set dirAlias to POSIX file theMachineDir as alias
		set theMachineDir to (POSIX path of (dirAlias as alias))
	end tell

	return {name:modelName, isBundle:isModelBundle, machineDirPath:theMachineDir, humanDirPath:theHumanDir}

end getModelInfo

on logger(msg)
	do shell script "logger '" & msg & "'"
end logger

on addFilesFromPathToGroup(_project, modelItr, groupRef)
	tell application "Xcode"
		-- get the full path of the directory that the groupRef represents
		set groupPath to full path of groupRef

		--	Build a list of source files in the group's directory
		tell application "System Events"
			set modelSrcDirAlias to POSIX file groupPath as alias
			set fileList to (every file of modelSrcDirAlias whose (name ends with ".m" or name ends with ".mm" or name ends with ".h"))
			set pathList to {}
			repeat with fileItem in fileList
				set pathList to pathList & POSIX path of fileItem
			end repeat
		end tell

		--	Add the source files to the group and the model's targets, but only if they don't exist already
		set targetList to null
		repeat with pathItr in pathList
			tell groupRef
				set fileRefs to (every file reference of _project whose full path is pathItr)
				if (count of fileRefs) = 0 then
					set modelSrcFileRef to make new file reference with properties {full path:pathItr, name:name of (info for POSIX file pathItr)}
					if targetList is null then
						set targetList to my everyTargetWithBuildFilePath(_project, full path of modelItr)
					end if
					repeat with targetIndex from 1 to (count of targetList)
						set targetItr to item targetIndex of targetList
						add modelSrcFileRef to targetItr
					end repeat
				end if
			end tell
		end repeat
	end tell
end addFilesFromPathToGroup

property ASDScriptUniqueIdentifier : "Xmod.applescript"

tell application "Xcode"
	if not (exists active project document) then
		error "No active project. Please open an Xcode project and re-run the script."
	try
		my updateProjectXmod(project of active project document)
	on error errMsg
		my logger("Xmod.scpt exception: " & errMsg)
	end try
end tell

on updateProjectXmod(_project)
	tell application "Xcode"
		-- Iterate over every .xcdatamodel in the project.
		set modelList to every file reference of _project whose file kind is "wrapper.xcdatamodel"
		repeat with modelItr in modelList
			set theComments to the comments of modelItr
			if theComments contains "xmod" then

				set modelInfo to my getModelInfo(full path of modelItr)

				-- Figure out the model's parent group.
				-- Unversioned models are simple files so their group is the answer.
				-- Version models are bundles, which are represented as pseudo-groups in Xcode. You can't ask a pseudo-group for its parent group,
				-- so we discover it by querying project-wide all groups that contain the pseudo-group and using the first result.
				set modelItemRef to item 1 of (every item reference of _project whose full path is (full path of modelItr))
				set modelGroupRef to group of modelItemRef
				if isBundle of modelInfo then
					set modelGroupRef to item 1 of (every group of _project whose groups contains modelGroupRef)
				end if

				-- Create the .xcdatamodel related source group if necessary.
				if not (exists (every item reference of modelGroupRef whose full path is (srcDirPath of modelInfo))) then
					tell modelGroupRef
						make new group with properties {full path:(srcDirPath of modelInfo), name:(name of modelInfo)}
					end tell
				end if
				set modelSrcGroup to item 1 of (every item reference of modelGroupRef whose full path is (srcDirPath of modelInfo))
				tell modelSrcGroup to delete every item reference -- clear it out for population in case we didn't just create it

				-- Create the do shell script string and append any custom per model options to it
				set theScript to "/usr/bin/mogenerator --model '" & full path of modelItr & "' --output-dir '" & (srcDirPath of modelInfo) & "'"
				set theParagraphs to every paragraph of theComments
				repeat with theParagraph in theParagraphs
					if (length of the characters of theParagraph) is greater than 2 then
						set theToken to the first character of theParagraph & the second character of theParagraph
						if theToken is "--" then
							set theScript to theScript & " " & the text of theParagraph
						end if
					end if
				end repeat

				--	Meat.
				do shell script theScript

				--	Build a list of resulting source files.
				tell application "System Events"
					set modelSrcDirAlias to POSIX file (srcDirPath of modelInfo) as alias
					set humanHeaderFileList to (every file of modelSrcDirAlias whose name ends with ".h" and name does not start with "_")
					set humanSourceFileList to (every file of modelSrcDirAlias whose (name ends with ".m" or name ends with ".mm") and name does not start with "_")
					set machineHeaderFileList to (every file of modelSrcDirAlias whose name ends with ".h" and name starts with "_")
					set machineSourceFileList to (every file of modelSrcDirAlias whose (name ends with ".m" or name ends with ".mm") and name starts with "_")
					set fileList to humanSourceFileList & humanHeaderFileList & machineSourceFileList & machineHeaderFileList
					set pathList to {}
					repeat with fileItem in fileList
						set pathList to pathList & POSIX path of fileItem
					end repeat
				end tell

				--	Add the source files to the model's source group and the model's targets.
				set targetList to my everyTargetWithBuildFilePath(_project, full path of modelItr)
				repeat with pathItr in pathList
					tell modelSrcGroup
						set modelSrcFileRef to make new file reference with properties {full path:pathItr, name:name of (info for POSIX file pathItr)}
						repeat with targetIndex from 1 to (count of targetList)
							set targetItr to item targetIndex of targetList
							add modelSrcFileRef to targetItr
						end repeat
					end tell
				end repeat
			end if
		end repeat
	end tell
end updateProjectXmod

on everyTargetWithBuildFilePath(_project, _buildFilePath)
	set theResult to {}
	tell application "Xcode"
		repeat with targetItr in (every target of _project)
			repeat with buildFileItr in build files of targetItr
				if full path of file reference of buildFileItr is _buildFilePath then set theResult to theResult & {(targetItr as anything)}
			end repeat
		end repeat
	end tell
	return theResult
end everyTargetWithBuildFilePath

on getModelInfo(modelFileUnixPath)
	set modelFilePosixRef to POSIX file modelFileUnixPath
	set modelFileAlias to modelFilePosixRef as alias

	tell application "Finder"
		set modelFileFolder to folder of modelFileAlias

		set isModelBundle to name of modelFileFolder ends with ".xcdatamodeld"
		if isModelBundle then
			set modelFileAlias to (folder of modelFileAlias) as alias -- it's a bundle, go up one folder
			set modelFileFolder to folder of modelFileAlias
		end if

		set modelFileName to name of modelFileAlias
		if isModelBundle then
			set extensionLength to length of ".xcdatamodeld"
		else
			set extensionLength to length of ".xcdatamodel"
		end if

		set modelName to text 1 thru -(extensionLength + 1) of modelFileName -- pull off the extension
		if not (exists folder modelName of modelFileFolder) then
			make folder at modelFileFolder with properties {name:modelName}
		end if
		set modelSrcFolder to folder modelName of modelFileFolder
	end tell
	set srcDirPath to text 1 thru -2 of (POSIX path of (modelSrcFolder as alias)) -- kill the trailing slash
	return {name:modelName, isBundle:isModelBundle, srcDirPath:srcDirPath}
end getModelInfo

on logger(msg)
	do shell script "logger '" & msg & "'"
end logger


corrected "get path" functionality in Finder when no finder window is open

if application "Path Finder" is running then
    tell application "Path Finder"
        set target_path to "\"" & (the POSIX path of the target of the front finder window) & "\""
        return target_path
    end tell
else
tell application "Finder"
        try
            set target_path to (quoted form of POSIX path of (folder of the front window as alias))
        on error line number num
            set target_path to (path to home folder)
        end try
		return target_path
	end tell
end if

if application "Path Finder" is running then
    tell application "Path Finder"
        set target_path to "\"" & (the POSIX path of the target of the front finder window) & "\""
        return target_path
    end tell
else
tell application "Finder"
		set target_path to (quoted form of POSIX path of (folder of the front window as alias))
		return target_path
	end tell
end if


Fix some bugs in iChat growl

Fix some bugs in iChat growl

using terms from application "iChat"
  on message received message from theBuddy for textChat
    set whoDidIt to full name of theBuddy
    set buddyIcon to image of theBuddy

    tell application "System Events"
      set frontApp to name of first application process whose frontmost is true
    end tell

    if frontApp is not equal to "iChat" then
      tell application "GrowlHelperApp" -- ** the daemon that is behind the scenes
        -- Make a list of all the notification types that this script will ever send:
        set the allNotificationsList to {"IM Received"}

        -- Make a list of the notifications that will be enabled by default.
        set the enabledNotificationsList to {"IM Received"}

        -- Register our script with growl.
        register as application "iChat Growl AppleScript" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "iChat"

        if buddyIcon is equal to missing value then
          notify with name "IM Received" title whoDidIt description message application name "iChat Growl AppleScript" sticky no identifier whoDidIt
        else
          notify with name "IM Received" title whoDidIt description message application name "iChat Growl AppleScript" sticky no identifier whoDidIt image buddyIcon
        end if
      end tell
    end if
  end message received
end using terms from

using terms from application "iChat"
  on message received message from theBuddy for textChat
    set whoDidIt to full name of theBuddy
    set buddyIcon to image of theBuddy
    set window_name to "Not iChat"

    tell application "System Events"
      set frontApp to name of first application process whose frontmost is true
    end tell

    if frontApp is equal to "iChat"
      tell application frontApp
        if the (count of documents) is not 0 then
          set window_name to name of front window
        end if
      end tell
    end if

    if window_name is not equal to "Chat with " & whoDidIt then
      tell application "GrowlHelperApp" -- ** the daemon that is behind the scenes
        -- Make a list of all the notification types that this script will ever send:
        set the allNotificationsList to {"IM Received"}

        -- Make a list of the notifications that will be enabled by default.
        set the enabledNotificationsList to {"IM Received"}

        -- Register our script with growl.
        register as application "iChat Growl AppleScript" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "iChat"

        if buddyIcon is equal to missing value then
          notify with name "IM Received" title whoDidIt description message application name "iChat Growl AppleScript" sticky no
        else
          notify with name "IM Received" title whoDidIt description message application name "iChat Growl AppleScript" sticky no image buddyIcon
        end if
      end tell
    end if
  end message received
end using terms from


Add practice text area to lookup dialog

Add practice text area to lookup dialog

on run {input}
  try
    do shell script "$HOME/Dropbox\\ \\(Personal\\)/projects/plover-tools/plover-dictionary-lookup/dictlook -x " & "\"" & input & "\""
    display dialog result default answer "" buttons {"OK"} default button 1
  on error
    display dialog "No such luck." buttons {"OK"} default button 1
    beep
  end try
end run

on run {input}
  try
    do shell script "$HOME/Dropbox\\ \\(Personal\\)/projects/plover-tools/plover-dictionary-lookup/dictlook -x " & "\"" & input & "\""
    display dialog result buttons {"OK"} default button 1
  on error
    display dialog "No such luck." buttons {"OK"} default button 1
    beep
  end try
end run


changed it to be able to turn off wifi sharing with a second call

# If its on, it will turn off
# If its off, it will turn on

# Open System Preferences application
tell application "System Preferences"
	activate
end tell

# Open the Sharing preference pane
tell application "System Preferences"
	reveal (pane id "com.apple.preferences.sharing")
end tell

# Select the Internet Sharing checkbox.
tell application "System Events"
	tell process "System Preferences"
		tell window "Sharing"
			# Internet Sharing is row 7 in Mavericks.
			set _checkbox to checkbox 1 of row 7 of table 1 of scroll area 1 of group 1

			tell _checkbox

				# Recheck the checkbox.
				click _checkbox
				delay 1
			end tell
			if (exists sheet 1) then
				if (exists button "Turn Wi-Fi On" of sheet 1) then
					click button "Turn Wi-Fi On" of sheet 1
					delay 1
				end if
				click button "Start" of sheet 1
			end if
		end tell
	end tell
end tell

# Close System Preferences application
tell application "System Preferences"
	quit
end tell

# Open System Preferences application
tell application "System Preferences"
	activate
end tell

# Open the Sharing preference pane
tell application "System Preferences"
	reveal (pane id "com.apple.preferences.sharing")
end tell

# Select the Internet Sharing checkbox.
tell application "System Events"
	tell process "System Preferences"
		tell window "Sharing"
			# Internet Sharing is row 7 in Mavericks.
			set _checkbox to checkbox 1 of row 7 of table 1 of scroll area 1 of group 1

			tell _checkbox
				# If the checkbox is checked then uncheck.
				if (its value as boolean) then click _checkbox
				delay 1

				# Recheck the checkbox.
				click _checkbox
				delay 1
			end tell
			if (exists sheet 1) then
				if (exists button "Turn Wi-Fi On" of sheet 1) then
					click button "Turn Wi-Fi On" of sheet 1
					delay 1
				end if
				click button "Start" of sheet 1
			end if
		end tell
	end tell
end tell

# Close System Preferences application
tell application "System Preferences"
	quit
end tell


moveForMon.applescript, from darwin11

moveForMon.applescript, from darwin11

property DEBUG_LEVEL : 1

on moveForMon(all)
	-- 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
	-- GeekTool
	set w_gtCal to 2
	set w_gtGcal to 3
	set w_gtTask to 4
	set w_gtPs to 1
	-- XRG
	set w_XRG to 1

	-- x posiiotn for dual/single monitor mode
	set ledgeDual to -160
	set ledgeSingle to 1280
	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 + 105
	set y_gtTask to y_gtGcal + 180
	set y_gtPs to y_gtTask + 90
	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
	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
	set dPosY to item 2 of svs
	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
	set dPosY_R to dPosY
	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
		set ledge to ledgeDual
		if DEBUG_LEVEL > 0 then
			log "ledge to ledgeDual"
		end if
	else
		set ledge to ledgeSingle
		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
			log ledge & y_gtCal
			log ledge & y_gtGcal
			log ledge & y_gtTask
			log ledge & y_gtPs
			set appName to "GeekTool"
			tell process appName
				set nW to number of windows
				--display dialog appName & " in process, nWindows=" & nW
				tell window w_gtCal
					-- set size to {1000, 1000}
					set position to {ledge, y_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

	-- 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
								log appName & " " & i
								if appName is in halfSizeApp_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, xsize:0.7, ysize:0.7})
								else if appName is in halfSizeApp_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, xsize:0.7, ysize:0.7})
								else if appName is in noResizeApp_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, resize:0})
								else if appName is in noResizeApp_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, resize:0})
								else if appName is in app_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L})
								else if appName is in app_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R})
								end if
							end repeat
						end tell
					end try
				end tell
			end if
		end repeat
	end if
end moveForMon

on run
	moveForMon(false)
end run

property DEBUG_LEVEL : 1

on moveForMon(all)
	-- 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
	-- GeekTool
	set w_gtCal to 2
	set w_gtGcal to 3
	set w_gtTask to 4
	set w_gtPs to 1
	-- XRG
	set w_XRG to 1

	-- x posiiotn for dual/single monitor mode
	set ledgeDual to -160
	set ledgeSingle to 1280
	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 + 105
	set y_gtTask to y_gtGcal + 170
	set y_gtPs to y_gtTask + 50
	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
	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
	set dPosY to item 2 of svs
	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
	set dPosY_R to dPosY
	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
		set ledge to ledgeDual
		if DEBUG_LEVEL > 0 then
			log "ledge to ledgeDual"
		end if
	else
		set ledge to ledgeSingle
		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
			log ledge & y_gtCal
			log ledge & y_gtGcal
			log ledge & y_gtTask
			log ledge & y_gtPs
			set appName to "GeekTool"
			tell process appName
				set nW to number of windows
				--display dialog appName & " in process, nWindows=" & nW
				tell window w_gtCal
					-- set size to {1000, 1000}
					set position to {ledge, y_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

	-- 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
								log appName & " " & i
								if appName is in halfSizeApp_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, xsize:0.7, ysize:0.7})
								else if appName is in halfSizeApp_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, xsize:0.7, ysize:0.7})
								else if appName is in noResizeApp_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L, resize:0})
								else if appName is in noResizeApp_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R, resize:0})
								else if appName is in app_L then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L})
								else if appName is in app_R then
									windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_R, monPosY:dPosY_R})
								end if
							end repeat
						end tell
					end try
				end tell
			end if
		end repeat
	end if
end moveForMon

on run
	moveForMon(false)
end run