typo in fmGUI_ManageLayouts_Layout_CreateOrUpdate

-- fmGUI_ManageLayouts_Layout_CreateOrUpdate({layoutName:null})
-- Daniel A. Shockley, NYHTC
-- Create/Update a layout.

(*
HISTORY:
	2020-03-03 ( dshockley, hdu ): Updated as standalone function for fm-scripts git repository. Use clickObjectByCoords instead of clickObjFromHtcLib.
	-- 1.4 - 2017-06-14 ( eshagdar ): narrowed scope
	-- 1.3 - 2017-05-18 ( eshagdar ): updated for FM15.
	-- 1.2 - 2016-08-24 ( eshagdar ): wait until 'Layout Setup' window comes up.
	-- 1.1 - 2013-11-22 ( dshockley ): If oldLayoutName is specified, will look for and change layout name, even if otherwise doNotChangeExisting.

	-- TODO: NOT HANDLING SCRIPT TRIGGERS YET!!! 2013-11-20-dshockley

REQUIRES:
	clickObjectByCoords
	logConsole
	fmGUI_CheckboxSet
	fmGUI_DataViewer_Close
	fmGUI_ManageLayouts_LayoutFolderSelect
	fmGUI_ManageLayouts_Open
	fmGUI_ManageLayouts_PopupNewItemOfType
	fmGUI_ManageLayouts_Select
	fmGUI_PopupSet
	windowWaitUntil_FrontIS
*)

on run
	fmGUI_ManageLayouts_Layout_CreateOrUpdate({layoutName:"Directory"})
end run

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

on fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)
	-- version 1.4

	set defaultPrefs to {layoutName:null, oldLayoutName:null, doNotChangeExisting:false, baseTableName:null, layoutParentFolder:"", includeInLayoutMenus:0, menuSet:null, formViewEnabled:1, listViewEnabled:1, tableViewEnabled:1, defaultView:"Form View", scriptTriggers:{}}

	set layoutOptions to layoutOptions & defaultPrefs

	set layoutName to layoutName of layoutOptions
	set oldLayoutName to oldLayoutName of layoutOptions

	-- Select a Layout and Edit it, or create it if it didn't exist yet.
	try
		fmGUI_DataViewer_Close()
		fmGUI_ManageLayouts_Open({})

		-- INIT:
		set foundThisLayout to false
		set foundOldLayout to false
		set layoutSelected to false

		set foundThisLayout to fmGUI_ManageLayouts_Select({layoutName:layoutName})
		set layoutSelected to foundThisLayout

		if oldLayoutName is not null then
			set foundOldLayout to fmGUI_ManageLayouts_Select({layoutName:oldLayoutName})
			if foundThisLayout and foundOldLayout then
				error "Couldn't fmGUI_ManageLayouts_Layout_CreateOrUpdate: Both the old '" & oldLayoutName & "' and the 'new' layout name '" & layoutName & "' already exist - PROBLEM!"
			else if foundOldLayout then
				set layoutSelected to true
			end if

		end if

		tell application "System Events"
			tell application process "FileMaker Pro Advanced"
				set manageLayoutsWindow to window 1
			end tell
		end tell

		if layoutSelected then
			if doNotChangeExisting of layoutOptions and not foundOldLayout then
				-- do NOT change if it already exists with the correct name.
			else
				-- exists and was selected, so click Edit:

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						set buttonRef to first button of manageLayoutsWindow whose title is "Edit"
					end tell
				end tell

				clickObjectByCoords(buttonRef)
				windowWaitUntil_FrontIS({windowName:"Layout Setup"})

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						set layoutSetupDialog to window 1
						set interfaceParent to tab group 1 of layoutSetupDialog

						if foundOldLayout then
							-- need to rename this layout:
							set value of text field "Layout Name" of interfaceParent to layoutName
						end if
					end tell
				end tell

				if doNotChangeExisting of layoutOptions then

				else -- ALLOWED to CHANGE the other properties of the layout:
					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							click (first radio button of interfaceParent whose name is "General")
							set showRecordsButton to pop up button "Show records from:" of interfaceParent
							set inludeInMenuButton to checkbox "Include in layout menus" of interfaceParent
							set menuSetButton to pop up button "Menu Set:" of interfaceParent
						end tell
					end tell

					if baseTableName of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(showRecordsButton), objValue:baseTableName of layoutOptions})
					if includeInLayoutMenus of layoutOptions is not null then fmGUI_CheckboxSet(inludeInMenuButton, includeInLayoutMenus of layoutOptions)
					if menuSet of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(menuSetButton), objValue:menuSet of layoutOptions})

					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							click (first radio button of interfaceParent whose name is "Views")
							set formCheckbox to checkbox "Form View" of interfaceParent
							set listCheckbox to checkbox "List View" of interfaceParent
							set tableCheckbox to checkbox "Table View" of interfaceParent
							set defaultButton to pop up button "Default view:" of interfaceParent
						end tell
					end tell

					if formViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(formCheckbox, formViewEnabled of layoutOptions)
					if listViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(listCheckbox, listViewEnabled of layoutOptions)
					if tableViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(tableCheckbox, tableViewEnabled of layoutOptions)
					if defaultView of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(defaultButton), objValue:defaultView of layoutOptions})

				end if

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						click button "OK" of layoutSetupDialog
					end tell
				end tell
			end if

			-- END IF: existing to edit.

		else
			-- BEGIN: does not exist - need to create it:

			if length of (layoutParentFolder of layoutOptions) is greater than 0 then
				-- create it IN a layout folder:
				-- Select the folder, or create it if it doesn't exist yet:
				if not fmGUI_ManageLayouts_LayoutFolderSelect(layoutParentFolder of layoutOptions) then
					fmGUI_ManageLayouts_PopupNewItemOfType("Folder")
					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							set value of text field "Folder Name:" of window 1 to layoutParentFolder of layoutOptions
							click button "OK" of window 1
							set newFolderRow to first row of (outline 1 of scroll area 1 of manageLayoutsWindow) whose value of text field 1 of group 1 is layoutParentFolder of layoutOptions
							set checkboxRef to checkbox 1 of newFolderRow
						end tell
					end tell
					fmGUI_CheckboxSet(checkboxRef, 1)

				end if
			end if

			-- Create the layout:
			if debugMode then logConsole(ScriptName, "creating layout: " & (layoutName of layoutOptions))
			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					set buttonRef to first button of manageLayoutsWindow whose title is "New"
				end tell
			end tell

			-- BEGIN: NEW WINDOW CODE
			clickObjectByCoords(buttonRef)
			windowWaitUntil_FrontIS({windowName:"New Layout/Report"})

			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					set newLayoutDialog to window 1
					set value of text field 1 of newLayoutDialog to layoutName of layoutOptions
					set buttonRef to pop up button 1 of newLayoutDialog
				end tell
			end tell
			fmGUI_PopupSet({objRef:my coerceToString(buttonRef), objValue:baseTableName of layoutOptions})
			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					click button 4 of newLayoutDialog -- select 'Computer'
					click button 6 of newLayoutDialog -- select 'Form'

					-- we don't care which mode to view in, so Finish:
					click button "Finish" of newLayoutDialog
				end tell
			end tell

			delay 1

			-- Now, believe it or not, need to call ITSELF since not all options available during Create:
			fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)

			-- END IF: does not exist - need to create it.
		end if

		return true
	on error errMsg number errNum
		error "unable to fmGUI_ManageLayouts_Layout_CreateOrUpdate '" & layoutName of layoutOptions & "' - " & errMsg number errNum
	end try

end fmGUI_ManageLayouts_Layout_CreateOrUpdate

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

on clickObjectByCoords(prefs)
	tell application "htcLib" to clickObjectByCoords(my coerceToString(prefs))
end clickObjectByCoords

on fmGUI_CheckboxSet(prefs)
	set objRefStr to coerceToString(objRef of prefs)
	tell application "htcLib" to fmGUI_CheckboxSet({objRef:objRefStr} & prefs)
end fmGUI_CheckboxSet

on fmGUI_DataViewer_Close()
	tell application "htcLib" to fmGUI_DataViewer_Close()
end fmGUI_DataViewer_Close

on fmGUI_ManageLayouts_LayoutFolderSelect(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_LayoutFolderSelect(prefs)
end fmGUI_ManageLayouts_LayoutFolderSelect

on fmGUI_ManageLayouts_Open(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_Open(prefs)
end fmGUI_ManageLayouts_Open

on fmGUI_ManageLayouts_PopupNewItemOfType(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_PopupNewItemOfType(prefs)
end fmGUI_ManageLayouts_PopupNewItemOfType

on fmGUI_ManageLayouts_Select(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_Select(prefs)
end fmGUI_ManageLayouts_Select

on fmGUI_PopupSet(prefs)
	set objRefStr to coerceToString(objRef of prefs)
	tell application "htcLib" to fmGUI_PopupSet({objRef:objRefStr} & prefs)
end fmGUI_PopupSet

on logConsole(prefs)
	tell application "htcLib" to logConsole(prefs)
end logConsole

on windowWaitUntil_FrontIS(prefs)
	tell application "htcLib" to windowWaitUntil_FrontIS(prefs)
end windowWaitUntil_FrontIS

on coerceToString(incomingObject)
	-- 2017-07-12 ( eshagdar ): bootstrap code to bring a coerceToString into this file for the sample to run ( instead of having a copy of the handler locally ).

	tell application "Finder" to set coercePath to (container of (container of (path to me)) as text) & "text parsing:coerceToString.applescript"
	set codeCoerce to read file coercePath as text
	tell application "htcLib" to set codeCoerce to "script codeCoerce " & return & getTextBetween({sourceText:codeCoerce, beforeText:"-- START OF CODE", afterText:"-- END OF CODE"}) & return & "end script" & return & "return codeCoerce"
	set codeCoerce to run script codeCoerce
	tell codeCoerce to coerceToString(incomingObject)
end coerceToString

-- fmGUI_ManageLayouts_Layout_CreateOrUpdate({layoutName:null})
-- Daniel A. Shockley, NYHTC
-- Create/Update a layout.

(*
HISTORY:
	2020-03-03 ( dshockley, hdu ): Updated as standalone function for fm-scripts git repository. Use clickObjectByCoords instead of clickObjFromHtcLib.
	-- 1.4 - 2017-06-14 ( eshagdar ): narrowed scope
	-- 1.3 - 2017-05-18 ( eshagdar ): updated for FM15.
	-- 1.2 - 2016-08-24 ( eshagdar ): wait until 'Layout Setup' window comes up.
	-- 1.1 - 2013-11-22 ( dshockley ): If oldLayoutName is specified, will look for and change layout name, even if otherwise doNotChangeExisting.

	-- TODO: NOT HANDLING SCRIPT TRIGGERS YET!!! 2013-11-20-dshockley

REQUIRES:
	clickObjectByCoords
	logConsole
	fmGUI_CheckboxSet
	fmGUI_DataViewer_Close
	fmGUI_ManageLayouts_LayoutFolderSelect
	fmGUI_ManageLayouts_Open
	fmGUI_ManageLayouts_PopupNewItemOfType
	fmGUI_ManageLayouts_Select
	fmGUI_PopupSet
	windowWaitUntil_FrontIS
*)

on run
	fmGUI_ManageLayouts_Layout_CreateOrUpdate({layoutName:"Directory"})
end run

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

on fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)
	-- version 1.4

	set defaultPrefs to {layoutName:null, oldLayoutName:null, doNotChangeExisting:false, baseTableName:null, layoutParentFolder:"", includeInLayoutMenus:0, menuSet:null, formViewEnabled:1, listViewEnabled:1, tableViewEnabled:1, defaultView:"Form View", scriptTriggers:{}}

	set layoutOptions to layoutOptions & defaultPrefs

	set layoutName to layoutName of layoutOptions
	set oldLayoutName to oldLayoutName of layoutOptions

	-- Select a Layout and Edit it, or create it if it didn't exist yet.
	try
		fmGUI_DataViewer_Close()
		fmGUI_ManageLayouts_Open({})

		-- INIT:
		set foundThisLayout to false
		set foundOldLayout to false
		set layoutSelected to false

		set foundThisLayout to fmGUI_ManageLayouts_Select({layoutName:layoutName})
		set layoutSelected to foundThisLayout

		if oldLayoutName is not null then
			set foundOldLayout to fmGUI_ManageLayouts_Select({layoutName:oldLayoutName})
			if foundThisLayout and foundOldLayout then
				error "Couldn't fmGUI_ManageLayouts_Layout_CreateOrUpdate: Both the old '" & oldLayoutName & "' and the 'new' layout name '" & layoutName & "' already exist - PROBLEM!"
			else if foundOldLayout then
				set layoutSelected to true
			end if

		end if

		tell application "System Events"
			tell application process "FileMaker Pro Advanced"
				set manageLayoutsWindow to window 1
			end tell
		end tell

		if layoutSelected then
			if doNotChangeExisting of layoutOptions and not foundOldLayout then
				-- do NOT change if it already exists with the correct name.
			else
				-- exists and was selected, so click Edit:

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						set buttonRef to first button of manageLayoutsWindow whose title is "Edit"
					end tell
				end tell

				clickObjectByCoords(buttonRef)
				windowWaitUntil_FrontIS({windowName:"Layout Setup"})

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						set layoutSetupDialog to window 1
						set interfaceParent to tab group 1 of layoutSetupDialog

						if foundOldLayout then
							-- need to rename this layout:
							set value of text field "Layout Name" of interfaceParent to layoutName
						end if
					end tell
				end tell

				if doNotChangeExisting of layoutOptions then

				else -- ALLOWED to CHANGE the other properties of the layout:
					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							click (first radio button of interfaceParent whose name is "General")
							set showRecordsButton to pop up button "Show records from:" of interfaceParent
							set inludeInMenuButton to checkbox "Include in layout menus" of interfaceParent
							set menuSetButton to pop up button "Menu Set:" of interfaceParent
						end tell
					end tell

					if baseTableName of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(showRecordsButton), objValue:baseTableName of layoutOptions})
					if includeInLayoutMenus of layoutOptions is not null then fmGUI_CheckboxSet(inludeInMenuButton, includeInLayoutMenus of layoutOptions)
					if menuSet of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(menuSetButton), objValue:menuSet of layoutOptions})

					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							click (first radio button of interfaceParent whose name is "Views")
							set formCheckbox to checkbox "Form View" of interfaceParent
							set listCheckbox to checkbox "List View" of interfaceParent
							set tableCheckbox to checkbox "Table View" of interfaceParent
							set defaultButton to pop up button "Default view:" of interfaceParent
						end tell
					end tell

					if formViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(formCheckbox, formViewEnabled of layoutOptions)
					if listViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(listCheckbox, listViewEnabled of layoutOptions)
					if tableViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet(tableCheckbox, tableViewEnabled of layoutOptions)
					if defaultView of layoutOptions is not null then fmGUI_PopupSet({objRef:my coerceToString(defaultButton), objValue:defaultView of layoutOptions})

				end if

				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						click button "OK" of layoutSetupDialog
					end tell
				end tell
			end if

			-- END IF: existing to edit.

		else
			-- BEGIN: does not exist - need to create it:

			if length of (layoutParentFolder of layoutOptions) is greater than 0 then
				-- create it IN a layout folder:
				-- Select the folder, or create it if it doesn't exist yet:
				if not fmGUI_ManageLayouts_LayoutFolderSelect(layoutParentFolder of layoutOptions) then
					fmGUI_ManageLayouts_PopupNewItemOfType("Folder")
					tell application "System Events"
						tell application process "FileMaker Pro Advanced"
							set value of text field "Folder Name:" of window 1 to layoutParentFolder of layoutOptions
							click button "OK" of window 1
							set newFolderRow to first row of (outline 1 of scroll area 1 of manageLayoutsWindow) whose value of text field 1 of group 1 is layoutParentFolder of layoutOptions
							set checkboxRef to checkbox 1 of newFolderRow
						end tell
					end tell
					fmGUI_CheckboxSet(checkboxRef, 1)

				end if
			end if

			-- Create the layout:
			if debugMode then logConsole(ScriptName, "creating layout: " & (layoutName of layoutOptions))
			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					set buttonRef to first button of manageLayoutsWindow whose title is "New"
				end tell
			end tell

			-- BEGIN: NEW WINDOW CODE
			clickObjectByCoords(buttonRef)
			windowWaitUntil_FrontIS({windowName:"New Layout/Report"})

			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					set newLayoutDialog to window 1
					set value of text field 1 of newLayoutDialog to layoutName of layoutOptions
					set buttonRef to pop up button 1 of newLayoutDialog
				end tell
			end tell
			mGUI_PopupSet({objRef:my coerceToString(buttonRef), objValue:baseTableName of layoutOptions})
			tell application "System Events"
				tell application process "FileMaker Pro Advanced"
					click button 4 of newLayoutDialog -- select 'Computer'
					click button 6 of newLayoutDialog -- select 'Form'

					-- we don't care which mode to view in, so Finish:
					click button "Finish" of newLayoutDialog
				end tell
			end tell

			delay 1

			-- Now, believe it or not, need to call ITSELF since not all options available during Create:
			fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)

			-- END IF: does not exist - need to create it.
		end if

		return true
	on error errMsg number errNum
		error "unable to fmGUI_ManageLayouts_Layout_CreateOrUpdate '" & layoutName of layoutOptions & "' - " & errMsg number errNum
	end try

end fmGUI_ManageLayouts_Layout_CreateOrUpdate

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

on clickObjectByCoords(prefs)
	tell application "htcLib" to clickObjectByCoords(my coerceToString(prefs))
end clickObjectByCoords

on fmGUI_CheckboxSet(prefs)
	set objRefStr to coerceToString(objRef of prefs)
	tell application "htcLib" to fmGUI_CheckboxSet({objRef:objRefStr} & prefs)
end fmGUI_CheckboxSet

on fmGUI_DataViewer_Close()
	tell application "htcLib" to fmGUI_DataViewer_Close()
end fmGUI_DataViewer_Close

on fmGUI_ManageLayouts_LayoutFolderSelect(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_LayoutFolderSelect(prefs)
end fmGUI_ManageLayouts_LayoutFolderSelect

on fmGUI_ManageLayouts_Open(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_Open(prefs)
end fmGUI_ManageLayouts_Open

on fmGUI_ManageLayouts_PopupNewItemOfType(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_PopupNewItemOfType(prefs)
end fmGUI_ManageLayouts_PopupNewItemOfType

on fmGUI_ManageLayouts_Select(prefs)
	tell application "htcLib" to fmGUI_ManageLayouts_Select(prefs)
end fmGUI_ManageLayouts_Select

on fmGUI_PopupSet(prefs)
	set objRefStr to coerceToString(objRef of prefs)
	tell application "htcLib" to fmGUI_PopupSet({objRef:objRefStr} & prefs)
end fmGUI_PopupSet

on logConsole(prefs)
	tell application "htcLib" to logConsole(prefs)
end logConsole

on windowWaitUntil_FrontIS(prefs)
	tell application "htcLib" to windowWaitUntil_FrontIS(prefs)
end windowWaitUntil_FrontIS

on coerceToString(incomingObject)
	-- 2017-07-12 ( eshagdar ): bootstrap code to bring a coerceToString into this file for the sample to run ( instead of having a copy of the handler locally ).

	tell application "Finder" to set coercePath to (container of (container of (path to me)) as text) & "text parsing:coerceToString.applescript"
	set codeCoerce to read file coercePath as text
	tell application "htcLib" to set codeCoerce to "script codeCoerce " & return & getTextBetween({sourceText:codeCoerce, beforeText:"-- START OF CODE", afterText:"-- END OF CODE"}) & return & "end script" & return & "return codeCoerce"
	set codeCoerce to run script codeCoerce
	tell codeCoerce to coerceToString(incomingObject)
end coerceToString


Close both Vagrants

Close both Vagrants

set close_ubervu_vagrant to "cd ~/uberVU/puppet; vagrant halt -f;"
set close_hs_vagrant to "cd ~/hootsuite/dash-board; vagrant halt -f;"

-- close vagrant
tell application "iTerm"
	activate
	set myterm to (make new terminal)
	tell myterm
		launch session "Default"
		set mysession to current session
	end tell

	tell mysession
		write text close_ubervu_vagrant
		write text close_hs_vagrant
	end tell
end tell

set close_vagrant to "z puppet; vagrant halt -f;"

-- close vagrant
tell application "iTerm"
	activate
	set myterm to (make new terminal)
	tell myterm
		launch session "Default"
		set mysession to current session
	end tell

	tell mysession
		write text close_vagrant
	end tell

	delay 5
end tell

-- quit iTerm
ignoring application responses
	tell application "iTerm"
		quit
	end tell
end ignoring

delay 2
tell application "System Events" to keystroke return


Change session name to 'rspec'

Change session name to 'rspec'

-- execute_iterm.scpt
-- last change: 19 Jan 2013
---
-- this script require an argument that represent the command to execute

on run argv

    set command to (item 1 of argv)

    tell application "iTerm"

        try
            set mysession to current session of current terminal
        on error
            set myterm to (make new terminal)
            tell myterm
                launch session "rspec"
                set mysession to current session
            end tell
        end try

        -- execute the command
        tell mysession
            write text command
        end tell

    end tell

end run

-- execute_iterm.scpt
-- last change: 19 Jan 2013
---
-- this script require an argument that represent the command to execute

on run argv

    set command to (item 1 of argv)

    tell application "iTerm"

        try
            set mysession to current session of current terminal
        on error
            set myterm to (make new terminal)
            tell myterm
                launch session "Default"
                set mysession to current session
            end tell
        end try

        -- execute the command
        tell mysession
            write text command
        end tell

    end tell

end run


remove unused newline variable

remove unused newline variable

tell application "Finder"
	set json_path to file "json.scpt" of folder of (path to me)
end tell
set json to load script (json_path as alias)

on is_running(appName)
	tell application "System Events" to (name of processes) contains appName
end is_running

set reply to json's createDict()
if is_running("Hermes") then
	reply's setkv("running", true)
	set hermesInfo to json's createDict()
	tell application "Hermes"
		hermesInfo's setkv("state", playback state as string)
		hermesInfo's setkv("title", current song's title)
		hermesInfo's setkv("artist", current song's artist)
		hermesInfo's setkv("album", current song's album)
		hermesInfo's setkv("artwork", current song's artwork URL)
		hermesInfo's setkv("rating", current song's rating)
		hermesInfo's setkv("position", playback position as integer)
		hermesInfo's setkv("duration", current song duration as integer)
	end tell
	reply's setkv("info", hermesInfo)
else
	reply's setkv("running", false)
end if
return reply's toJson()

tell application "Finder"
	set json_path to file "json.scpt" of folder of (path to me)
end tell
set json to load script (json_path as alias)

on is_running(appName)
	tell application "System Events" to (name of processes) contains appName
end is_running

set nl to "
"

set reply to json's createDict()
if is_running("Hermes") then
	reply's setkv("running", true)
	set hermesInfo to json's createDict()
	tell application "Hermes"
		hermesInfo's setkv("state", playback state as string)
		hermesInfo's setkv("title", current song's title)
		hermesInfo's setkv("artist", current song's artist)
		hermesInfo's setkv("album", current song's album)
		hermesInfo's setkv("artwork", current song's artwork URL)
		hermesInfo's setkv("rating", current song's rating)
		hermesInfo's setkv("position", playback position as integer)
		hermesInfo's setkv("duration", current song duration as integer)
	end tell
	reply's setkv("info", hermesInfo)
else
	reply's setkv("running", false)
end if
return reply's toJson()


[#67] updated the Mac packager to latest version

Former-commit-id: a1d0217011facbdc5359bce120f3892890f95169

on run (volumeName)
	tell application "Finder"
		tell disk (volumeName as string)
			open

			set theXOrigin to WINX
			set theYOrigin to WINY
			set theWidth to WINW
			set theHeight to WINH

			set theBottomRightX to (theXOrigin + theWidth)
			set theBottomRightY to (theYOrigin + theHeight)
			set dsStore to "\"" & "/Volumes/" & volumeName & "/" & ".DS_STORE\""

			tell container window
				set current view to icon view
				set toolbar visible to false
				set statusbar visible to false
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
				set statusbar visible to false
				REPOSITION_HIDDEN_FILES_CLAUSE
			end tell

			set opts to the icon view options of container window
			tell opts
				set icon size to ICON_SIZE
				set text size to TEXT_SIZE
				set arrangement to not arranged
			end tell
			BACKGROUND_CLAUSE

			-- Positioning
			POSITION_CLAUSE

			-- Hiding
			HIDING_CLAUSE

			-- Application Link Clause
			APPLICATION_CLAUSE
            close
            open

			update without registering applications
			-- Force saving of the size
			delay 1

			tell container window
				set statusbar visible to false
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX - 10, theBottomRightY - 10}
			end tell

			update without registering applications
		end tell

		delay 1

		tell disk (volumeName as string)
			tell container window
				set statusbar visible to false
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
			end tell

			update without registering applications
		end tell

		--give the finder some time to write the .DS_Store file
		delay 3

		set waitTime to 0
		set ejectMe to false
		repeat while ejectMe is false
			delay 1
			set waitTime to waitTime + 1

			if (do shell script "[ -f " & dsStore & " ]; echo $?") = "0" then set ejectMe to true
		end repeat
		log "waited " & waitTime & " seconds for .DS_STORE to be created."
	end tell
end run

on run (volumeName)
	tell application "Finder"
		tell disk (volumeName as string)
			open

			set theXOrigin to WINX
			set theYOrigin to WINY
			set theWidth to WINW
			set theHeight to WINH

			set theBottomRightX to (theXOrigin + theWidth)
			set theBottomRightY to (theYOrigin + theHeight)
			set dsStore to "\"" & "/Volumes/" & volumeName & "/" & ".DS_STORE\""

			tell container window
				set current view to icon view
				set toolbar visible to false
				set statusbar visible to false
				-- set position of every item to {theBottomRightX + 100, 100}
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
				set statusbar visible to false
			end tell

			set opts to the icon view options of container window
			tell opts
				set icon size to ICON_SIZE
				set text size to TEXT_SIZE
				set arrangement to not arranged
			end tell
			BACKGROUND_CLAUSE

			-- Positioning
			POSITION_CLAUSE

			-- Hiding
			HIDING_CLAUSE

			-- Application Link Clause
			APPLICATION_CLAUSE
            close
            open

			update without registering applications
			-- Force saving of the size
			delay 1

			tell container window
				set statusbar visible to false
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX - 10, theBottomRightY - 10}
			end tell

			update without registering applications
		end tell

		delay 1

		tell disk (volumeName as string)
			tell container window
				set statusbar visible to false
				set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
			end tell

			update without registering applications
		end tell

		--give the finder some time to write the .DS_Store file
		delay 3

		set waitTime to 0
		set ejectMe to false
		repeat while ejectMe is false
			delay 1
			set waitTime to waitTime + 1

			if (do shell script "[ -f " & dsStore & " ]; echo $?") = "0" then set ejectMe to true
		end repeat
		log "waited " & waitTime & " seconds for .DS_STORE to be created."
	end tell
end run


Fix centering of button names broken in Mavericks

Padding is used to increase the button width in dialogs in order to
increase the width of the dialogs themselves (for wider text fields).


handle viscosity errors more gracefully

handle viscosity errors more gracefully

#!/usr/bin/osascript

try
	tell application "Viscosity"
		if the state of the first connection is not "Connected" then
			connect the first connection

			repeat until state of the first connection is "Connected"
				delay 1
			end repeat
		end if
	end tell
on error
	tell me to quit
end try

#!/usr/bin/osascript

tell application "Viscosity"
  if the state of the first connection is not "Connected" then
    connect the first connection

    repeat until state of the first connection is "Connected"
      delay 1
    end repeat
  end if
end tell


converted to UTF-8

converted to UTF-8