windowSizeAll.applescript, from darwin11

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

-- 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(100, 100)
set dPosX to (item 1 of svs) + 100
set dPosY to (item 2 of svs) + 100
set dWidth to item 3 of svs
set dHeight to item 4 of svs

-- try to get left screen
set dPosX_L to dPosX
set dPosY_L to dPosY
try
	set svsL to windowSize's getVisibleFrame(-100, 100)
	set dPosX_L to (item 1 of svsL) + 100
	set dPosY_L to (item 2 of svsL) + 100
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 + 100, 100)
	set dPosX_R to (item 1 of svsR) + 100
	set dPosY_R to (item 2 of svsR) + 100
end try

log "dPosX:" & dPosX & ", dPosY:" & dPosY & ", dPosX_L:" & dPosX_L & ", dPosY_L:" & dPosY_L & ", dPosX_R:" & dPosX_R & ",dPosY_R:" & dPosY_R

-- 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
					--display dialog appName & " " & nW

					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
							log "app_L" & appName & ", windowSize(" & appName & "," & i & "," & dPosX_L & "," & dPosY_L & ")"

							windowSize's windowSize({appName:appName, windowNumber:i, monPosX:dPosX_L, monPosY:dPosY_L})
						else if appName is in app_R then
							log "app_R" & appName
							--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


moveForMon.applescript, from darwin19

moveForMon.applescript, from darwin19

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


RestoreApp.scpt is no longer used

RestoreApp.scpt is no longer used

-- see: http://lists.apple.com/archives/Applescript-users/2007/Mar/msg00265.html

-- related issues:
--   Visor launches app when returning focus (http://github.com/darwin/visor/issues#issue/8)
--   Visor crashes when trying to return focus to non-running application? (http://github.com/darwin/visor/issues#issue/12)

on restoreApp(appName)
    with timeout of 1 second
        tell application appName
            activate
        end tell
    end timeout
end restoreApp

restoreApp("%@")


Fix up clear notifs to put all into a handler

FasdUAS 1.101.10
k
i
I(0clearnotificationsclearNotifications
k

I
.miscactvnullnull
m

@alispMacintosh HDBDNotificationCenter.app
 cuCoreServices5/:System:Library:CoreServices:NotificationCenter.app/.NotificationCenter.appMacintosh HD2System/Library/CoreServices/NotificationCenter.app/
O
O

T
k
l
Q1
r(
n&
4#&

sgrp
 m$%
n#!"
!4 ##

uiel
#m!"
"n $%
$4 &

scra
&m
%4'

cwin
'm(())&Notification Center
o0	thewindow	theWindow
R
.ascrerr ********
S01*+
*l22+,
,Q2-.
-k5//01
0r5:23
2n5845
4268

actT
5o560	thewindow	theWindow
3o0
theactions
theActions167
6l;;789
8l;;:;:SM Try to close the whole group first. If that fails, close individual windows.;<< Try to close the whole group first. If that fails, close individual windows.9=>
=X;p?@
?ZKkAB
A=KTCD
CnKPEF
E1LP

desc
FoKL0	theaction	theAction
DmPSGGHHClear All
BkWgIIJK
JrWZLM
LmWX
boovtrue
Mo
0closedKNO
NO[ePQ
PI_dR
.prcsperfnullactT
Ro_`0	theaction	theAction
Qo[\0	thewindow	theWindowOS
SSfg0	theaction	theAction
@o>?0
theactions
theActions>TU
TlqqUVW
VXqXY
XZZ[
Z=\]
\n^_
^1

desc
_o0	theaction	theAction
]m``aa
Close
[kbbcd
cref
em
boovtrue
fo
0closeddgh
gOij
iIk
.prcsperfnullactT
ko0	theaction	theAction
jo0	thewindow	theWindowhl
lS0	theaction	theAction
Yotu0
theactions
theActionsWm
ml
.R
.ascrerr ********
4
n

prcs
nm
oopp&Notification Center
mqqsevsalis\Macintosh HDBDSystem Events.app
 cuCoreServices0/:System:Library:CoreServices:System Events.app/$System Events.appMacintosh HD-System/Library/CoreServices/System Events.app/rs
rlst
tlu
uI(0clearnotificationsclearNotificationsvwxv(0clearnotificationsclearNotifications
.aevtoappnull****wyz(0clearnotificationsclearNotificationsy0	thewindow	theWindow0
theactions
theActions0	theaction	theAction
0closedz
qo(G`
.miscactvnullnull

prcs

cwin

scra

uiel

sgrp

actT

kocl

cobj
.corecnte********

desc
.prcsperfnullactTjO*/hZ*/k/k/k/EWX
Ox-EO4[lkha,aeEOjUOYh[OYO4[lkha,aeEOjUOYh[OYOPWX
h[OYaUUx{|}
.aevtoappnull****
{k~~t|}(0clearnotificationsclearNotifications*j+ascrޭ

FasdUAS 1.101.10
k
l
I
.miscactvnullnull
m		@alispMacintosh HDBDNotificationCenter.app
 cuCoreServices5/:System:Library:CoreServices:NotificationCenter.app/.NotificationCenter.appMacintosh HD2System/Library/CoreServices/NotificationCenter.app/

l
O

O

T
k
l
Q1
r(
n&
4#&

sgrp
m$%
n#
4 #

uiel
 m!"
n !"
!4 #

scra
#m
"4$

cwin
$m%%&&&Notification Center
o0	thewindow	theWindow
R
.ascrerr ********
S01'(
'l22()
)Q2*+
*k5,,-.
-r5:/0
/n5812
1268

actT
2o560	thewindow	theWindow
0o0
theactions
theActions.34
3l;;456
5l;;787SM Try to close the whole group first. If that fails, close individual windows.899 Try to close the whole group first. If that fails, close individual windows.6:;
:X;t<=
<ZMo>?
>=MV@A
@nMRBC
B1NR

desc
CoMN0	theaction	theAction
AmRUDDEEClear All
?kYkFFGH
GrY^IJ
ImYZ
boovtrue
Jo
0closedHKL
KO_iMN
MIchO
.prcsperfnullactT
Oocd0	theaction	theAction
No_`0	thewindow	theWindowLP
PSjk0	theaction	theAction
=o>?0
theactions
theActions;QR
QluuRST
SXuUV
UZWX
W=YZ
Yn[\
[1

desc
\o0	theaction	theAction
Zm]]^^
Close
Xk__`a
`rbc
bm
boovtrue
co
0closedade
dOfg
fIh
.prcsperfnullactT
ho0	theaction	theAction
go0	thewindow	theWindowei
iS0	theaction	theAction
Voxy0
theactions
theActionsTj
jl
+R
.ascrerr ********
4
k

prcs
km
llmm&Notification Center

mnnsevsalis\Macintosh HDBDSystem Events.app
 cuCoreServices0/:System:Library:CoreServices:System Events.app/$System Events.appMacintosh HD-System/Library/CoreServices/System Events.app/opqro
.aevtoappnull****0	thewindow	theWindow0
theactions
theActions
0closedpstu
.aevtoappnull****
skvvww
t0	theaction	theActionu	nl%D]
.miscactvnullnull

prcs

cwin

scra

uiel

sgrp0	thewindow	theWindow

actT0
theactions
theActions

kocl

cobj
.corecnte********

desc
0closed
.prcsperfnullactTjO*/hZ*/k/k/k/EWXO-EO8[alkha,aeE`OjUOYh[OYO8[alkha,aeE`OjUOYh[OYOPWXh[OYYUUqxxyyzz{{|}|n~

pcap~$NotificationCenter

cwin}&Notification Center

scra

uiel

sgrprn

pcap$NotificationCenter

cwin&Notification Center

scra

uiel

sgrp

actT"AXScrollToVisiblen

pcap$NotificationCenter

cwin&Notification Center

scra

uiel

sgrp

actTAXShowMenu
boovtrueascr
ޭ


Fixed Terminal test script bugs.

Fixed Terminal test script bugs.

tell application "Terminal"
	activate
	set window_id to id of first window
	-- set project path
	set cd_path to "cd ~/Projects/Scalien/ScalienDB;"
	-- clear database
	set clearall_cmd to cd_path & "test/clearall"
	-- do script does not block while do shell script does
	--do script clearall_cmd in tab 1 of window id window_id
	do shell script clearall_cmd

	-- clear scrollbacks
	set twin to first window
	tell twin
		repeat with t from 1 to 6
			set selected of tab t to true
			my menu_click({"Terminal", "View", "Clear Scrollback"})
		end repeat
		set selected of tab 1 to true
	end tell

	-- start controllers
	repeat with c from 0 to 2
		set t to c + 1
		set cmd to cd_path & "test/runc " & c
		do script cmd in tab t of window id window_id
	end repeat

	-- start data nodes
	repeat with d from 0 to 2
		set t to d + 4
		set cmd to cd_path & "test/rund " & d
		do script cmd in tab t of window id window_id
	end repeat
end tell

-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item.  In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.

on menu_click(mList)
	local appName, topMenu, r

	-- Validate our input
	if mList's length < 3 then error "Menu list is not long enough"

	-- Set these variables for clarity and brevity later on
	set {appName, topMenu} to (items 1 through 2 of mList)
	set r to (items 3 through (mList's length) of mList)

	-- This overly-long line calls the menu_recurse function with
	-- two arguments: r, and a reference to the top-level menu
	tell application "System Events" to my menu_click_recurse(r, ((process appName)'s
		(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
	local f, r

	-- `f` = first item, `r` = rest of items
	set f to item 1 of mList
	if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

	-- either actually click the menu item, or recurse again
	tell application "System Events"
		if mList's length is 1 then
			click parentObject's menu item f
		else
			my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
		end if
	end tell
end menu_click_recurse

#!/usr/bin/osascript
tell application "Terminal"
	activate
end tell
menu_click({"Terminal", "View", "Clear Scrollback"})
tell application "Terminal"
	set window_id to id of first window whose frontmost is true
	-- set project path
	set cd_path to "cd ~/Projects/Scalien/ScalienDB;"

	-- clear database
	set cmd to cd_path & "test/clearall"
	do script cmd in tab 1 of window id window_id

	-- start controllers
	repeat with c from 0 to 2
		set t to c + 1
		set cmd to cd_path & "test/runc " & c
		do script cmd in tab t of window id window_id
	end repeat

	-- start data nodes
	repeat with d from 0 to 2
		set t to d + 4
		set cmd to cd_path & "test/rund " & d
		do script cmd in tab t of window id window_id
	end repeat
end tell

-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item.  In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.

on menu_click(mList)
	local appName, topMenu, r

	-- Validate our input
	if mList's length < 3 then error "Menu list is not long enough"

	-- Set these variables for clarity and brevity later on
	set {appName, topMenu} to (items 1 through 2 of mList)
	set r to (items 3 through (mList's length) of mList)

	-- This overly-long line calls the menu_recurse function with
	-- two arguments: r, and a reference to the top-level menu
	tell application "System Events" to my menu_click_recurse(r, ((process appName)'s
		(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
	local f, r

	-- `f` = first item, `r` = rest of items
	set f to item 1 of mList
	if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

	-- either actually click the menu item, or recurse again
	tell application "System Events"
		if mList's length is 1 then
			click parentObject's menu item f
		else
			my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
		end if
	end tell
end menu_click_recurse


Remove extra line breaker in pdf script

Remove extra line breaker in pdf script

############################
# How to generate the PDFs #
############################
# 1. Generate Cover.pdf with latest version date
#    a. Create "ebook" folder in ~/Downloads
#    b. update date in cover.html
#    c. open in safari file:///Users/frank/Sites/ServerlessStackCom/etc/cover.html
#    d. "Export to PDF…"
#    e. Place Cover.pdf in ~/ebook folder
# 2. Ensure "ebook" folder is an option when "Export to PDF…" in Safari
# 3. In terminal, run "osascript pdf.scpt"

set theChaptersStr to "index
who-is-this-guide-for
what-does-this-guide-cover
how-to-get-help
what-is-serverless
what-is-aws-lambda
why-create-serverless-apps
create-an-aws-account
create-an-iam-user
what-is-iam
what-is-an-arn
configure-the-aws-cli
create-a-dynamodb-table
create-an-s3-bucket-for-file-uploads
create-a-cognito-user-pool
create-a-cognito-test-user
setup-the-serverless-framework
add-support-for-es6-es7-javascript
add-a-create-note-api
add-a-get-note-api
add-a-list-all-the-notes-api
add-an-update-note-api
add-a-delete-note-api
deploy-the-apis
create-a-cognito-identity-pool
cognito-user-pool-vs-identity-pool
test-the-apis
create-a-new-reactjs-app
add-app-favicons
setup-custom-fonts
setup-bootstrap
handle-routes-with-react-router
create-containers
adding-links-in-the-navbar
handle-404s
configure-aws-amplify
create-a-login-page
login-with-aws-cognito
add-the-session-to-the-state
load-the-state-from-the-session
clear-the-session-on-logout
redirect-on-login-and-logout
give-feedback-while-logging-in
create-a-signup-page
create-the-signup-form
signup-with-aws-cognito
add-the-create-note-page
call-the-create-api
upload-a-file-to-s3
list-all-the-notes
call-the-list-api
display-a-note
render-the-note-form
save-changes-to-a-note
delete-a-note
setup-secure-pages
create-a-route-that-redirects
use-the-redirect-routes
redirect-on-login
deploy-the-frontend
create-an-s3-bucket
deploy-to-s3
create-a-cloudfront-distribution
setup-your-domain-with-cloudfront
setup-www-domain-redirect
setup-ssl
deploy-updates
update-the-app
deploy-again
getting-production-ready
initialize-the-backend-repo
organize-the-backend-repo
what-is-infrastructure-as-code
configure-dynamodb-in-serverless
configure-s3-in-serverless
configure-cognito-user-pool-in-serverless
configure-cognito-identity-pool-in-serverless
use-environment-variables-in-lambda-functions
deploy-your-serverless-infrastructure
working-with-3rd-party-apis
setup-a-stripe-account
add-a-billing-api
load-secrets-from-env-yml
test-the-billing-api
unit-tests-in-serverless
automating-serverless-deployments
setting-up-your-project-on-seed
configure-secrets-in-seed
deploying-through-seed
set-custom-domains-through-seed
test-the-configured-apis
monitoring-deployments-in-seed
initialize-the-frontend-repo
manage-environments-in-create-react-app
create-a-settings-page
add-stripe-keys-to-config
create-a-billing-form
connect-the-billing-form
automating-react-deployments
create-a-build-script
setting-up-your-project-on-netlify
custom-domain-in-netlify
frontend-workflow
wrapping-up
further-reading
giving-back
changelog
staying-up-to-date
organizing-serverless-projects
cross-stack-references-in-serverless
dynamodb-as-a-serverless-service
s3-as-a-serverless-service
api-gateway-domains-across-services
cognito-as-a-serverless-service
deploying-multiple-services-in-serverless
api-gateway-and-lambda-logs
debugging-serverless-api-issues
serverless-environment-variables
stages-in-serverless-framework
configure-multiple-aws-profiles
customize-the-serverless-iam-policy
mapping-cognito-identity-id-and-user-pool-id
connect-to-api-gateway-with-iam-auth
serverless-nodejs-starter
manage-user-accounts-in-aws-amplify
handle-forgot-and-reset-password
allow-users-to-change-passwords
allow-users-to-change-their-email
code-splitting-in-create-react-app
environments-in-create-react-app
facebook-login-with-cognito-using-aws-amplify"

set text item delimiters to "
"

set theChapters to text items of theChaptersStr

########
# Main #
########
downloadPdfs(theChapters)
mergePdfs(theChapters)

##############
# Merge PDFs #
##############
on mergePdfs(theChapters)
  set outputFile to "~/Downloads/ebook/ServerlessStack.pdf"

  set pdfFiles to "~/Downloads/ebook/Cover.pdf"
  repeat with theCurrentChapter in theChapters
    set pdfFiles to pdfFiles & " ~/Downloads/ebook/" & theCurrentChapter & ".pdf"
  end repeat

  do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & outputFile & " " & pdfFiles
end mergePdfs

#################
# Download PDFs #
#################
on downloadPdfs(theChapters)
  repeat with theCurrentChapter in theChapters
    if not(checkFileExist(theCurrentChapter)) then
      downloadPdf(theCurrentChapter)
    end if
  end repeat
end downloadPdfs

on checkFileExist(theChapterName)
  set basePath to POSIX path of (path to home folder) & "Downloads/ebook/"

  tell application "Finder"
    return exists basePath & theChapterName & ".pdf" as POSIX file
  end tell
end checkFileExist

on downloadPdf(theChapterName)
  tell application "System Events"

    tell process "Safari"
      set frontmost to true

      if ((theChapterName as string) is equal to "index") then
        set urlPath to theChapterName
      else
        set urlPath to "chapters/" & theChapterName
      end if
      open location "https://serverless-stack.com/" & urlPath & ".html"

      delay 1

      repeat until menu item "Export as PDF…" of menu "File" of menu bar 1 exists
        delay 0.2
      end repeat
      repeat until menu item "Export as PDF…" of menu "File" of menu bar 1 is enabled
        delay 0.2
      end repeat
      click menu item "Export as PDF…" of menu "File" of menu bar 1

      tell window 1
        repeat until sheet 1 exists
        end repeat

        tell sheet 1
          keystroke theChapterName
          click pop up button "Where:"

          repeat until menu 1 of pop up button "Where:" exists
          end repeat
          click menu item "ebook" of menu 1 of pop up button "Where:"
          click button "Save"
        end tell

      end tell

      click menu item "Close Tab" of menu "File" of menu bar 1

    end tell

  end tell
end downloadPdf

############################
# How to generate the PDFs #
############################
# 1. Generate Cover.pdf with latest version date
#    a. Create "ebook" folder in ~/Downloads
#    b. update date in cover.html
#    c. open in safari file:///Users/frank/Sites/ServerlessStackCom/etc/cover.html
#    d. "Export to PDF…"
#    e. Place Cover.pdf in ~/ebook folder
# 2. Ensure "ebook" folder is an option when "Export to PDF…" in Safari
# 3. In terminal, run "osascript pdf.scpt"

set theChaptersStr to "index
who-is-this-guide-for
what-does-this-guide-cover
how-to-get-help
what-is-serverless
what-is-aws-lambda
why-create-serverless-apps
create-an-aws-account
create-an-iam-user
what-is-iam
what-is-an-arn
configure-the-aws-cli
create-a-dynamodb-table
create-an-s3-bucket-for-file-uploads
create-a-cognito-user-pool
create-a-cognito-test-user
setup-the-serverless-framework
add-support-for-es6-es7-javascript
add-a-create-note-api
add-a-get-note-api
add-a-list-all-the-notes-api
add-an-update-note-api
add-a-delete-note-api
deploy-the-apis
create-a-cognito-identity-pool
cognito-user-pool-vs-identity-pool
test-the-apis
create-a-new-reactjs-app
add-app-favicons
setup-custom-fonts
setup-bootstrap
handle-routes-with-react-router
create-containers
adding-links-in-the-navbar
handle-404s
configure-aws-amplify
create-a-login-page
login-with-aws-cognito
add-the-session-to-the-state
load-the-state-from-the-session
clear-the-session-on-logout
redirect-on-login-and-logout
give-feedback-while-logging-in
create-a-signup-page
create-the-signup-form
signup-with-aws-cognito
add-the-create-note-page
call-the-create-api
upload-a-file-to-s3
list-all-the-notes
call-the-list-api
display-a-note
render-the-note-form
save-changes-to-a-note
delete-a-note
setup-secure-pages
create-a-route-that-redirects
use-the-redirect-routes
redirect-on-login
deploy-the-frontend
create-an-s3-bucket
deploy-to-s3
create-a-cloudfront-distribution
setup-your-domain-with-cloudfront
setup-www-domain-redirect
setup-ssl
deploy-updates
update-the-app
deploy-again
getting-production-ready
initialize-the-backend-repo
organize-the-backend-repo
what-is-infrastructure-as-code
configure-dynamodb-in-serverless
configure-s3-in-serverless
configure-cognito-user-pool-in-serverless
configure-cognito-identity-pool-in-serverless
use-environment-variables-in-lambda-functions
deploy-your-serverless-infrastructure
working-with-3rd-party-apis
setup-a-stripe-account
add-a-billing-api
load-secrets-from-env-yml
test-the-billing-api
unit-tests-in-serverless
automating-serverless-deployments
setting-up-your-project-on-seed
configure-secrets-in-seed
deploying-through-seed
set-custom-domains-through-seed
test-the-configured-apis
monitoring-deployments-in-seed
initialize-the-frontend-repo
manage-environments-in-create-react-app
create-a-settings-page
add-stripe-keys-to-config
create-a-billing-form
connect-the-billing-form
automating-react-deployments
create-a-build-script
setting-up-your-project-on-netlify
custom-domain-in-netlify
frontend-workflow
wrapping-up
further-reading
giving-back
changelog
staying-up-to-date
organizing-serverless-projects
cross-stack-references-in-serverless
dynamodb-as-a-serverless-service
s3-as-a-serverless-service
api-gateway-domains-across-services
cognito-as-a-serverless-service
deploying-multiple-services-in-serverless
api-gateway-and-lambda-logs
debugging-serverless-api-issues
serverless-environment-variables
stages-in-serverless-framework
configure-multiple-aws-profiles
customize-the-serverless-iam-policy
mapping-cognito-identity-id-and-user-pool-id
connect-to-api-gateway-with-iam-auth
serverless-nodejs-starter
manage-user-accounts-in-aws-amplify
handle-forgot-and-reset-password
allow-users-to-change-passwords
allow-users-to-change-their-email
code-splitting-in-create-react-app
environments-in-create-react-app
facebook-login-with-cognito-using-aws-amplify
"

set text item delimiters to "
"

set theChapters to text items of theChaptersStr

########
# Main #
########
downloadPdfs(theChapters)
mergePdfs(theChapters)

##############
# Merge PDFs #
##############
on mergePdfs(theChapters)
  set outputFile to "~/Downloads/ebook/ServerlessStack.pdf"

  set pdfFiles to "~/Downloads/ebook/Cover.pdf"
  repeat with theCurrentChapter in theChapters
    set pdfFiles to pdfFiles & " ~/Downloads/ebook/" & theCurrentChapter & ".pdf"
  end repeat

  do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & outputFile & " " & pdfFiles
end mergePdfs

#################
# Download PDFs #
#################
on downloadPdfs(theChapters)
  repeat with theCurrentChapter in theChapters
    if not(checkFileExist(theCurrentChapter)) then
      downloadPdf(theCurrentChapter)
    end if
  end repeat
end downloadPdfs

on checkFileExist(theChapterName)
  set basePath to POSIX path of (path to home folder) & "Downloads/ebook/"

  tell application "Finder"
    return exists basePath & theChapterName & ".pdf" as POSIX file
  end tell
end checkFileExist

on downloadPdf(theChapterName)
  tell application "System Events"

    tell process "Safari"
      set frontmost to true

      if ((theChapterName as string) is equal to "index") then
        set urlPath to theChapterName
      else
        set urlPath to "chapters/" & theChapterName
      end if
      open location "https://serverless-stack.com/" & urlPath & ".html"

      delay 1

      repeat until menu item "Export as PDF…" of menu "File" of menu bar 1 exists
        delay 0.2
      end repeat
      repeat until menu item "Export as PDF…" of menu "File" of menu bar 1 is enabled
        delay 0.2
      end repeat
      click menu item "Export as PDF…" of menu "File" of menu bar 1

      tell window 1
        repeat until sheet 1 exists
        end repeat

        tell sheet 1
          keystroke theChapterName
          click pop up button "Where:"

          repeat until menu 1 of pop up button "Where:" exists
          end repeat
          click menu item "ebook" of menu 1 of pop up button "Where:"
          click button "Save"
        end tell

      end tell

      click menu item "Close Tab" of menu "File" of menu bar 1

    end tell

  end tell
end downloadPdf


Do a git pull before vagrant halt because ops think we should halt Vagrant only with the latest version

set close_vagrant to "z puppet; git pull; 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

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


replicate - typo in comments

replicate - typo in comments

Scripts/fmClip - Replicate FM Objects.applescript