change `_read_file` to `read_file`

change `_read_file` to `read_file`

(* GLOBAL PROPERTIES

&& $? for bash status codes

*)
property BUNDLER_VERSION : "devel"
--# Bundler paths
property _home : POSIX path of (path to "cusr" as text)
property BUNDLER_DIR : (_home) & "Library/Application Support/Alfred 2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
property DATA_DIR : BUNDLER_DIR & "/data"
property CACHE_DIR : (_home) & "Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
--# Main Applescript Bundler
property AS_BUNDLER : BUNDLER_DIR & "/bundler/AlfredBundler.scpt"
--# Root directory under which workflow-specific applescript libraries are installed
property APPLESCRIPT_DIR : DATA_DIR & "/assets/applescript"
--# Root directory under which Bundler utilities are installed
property UTILITIES_DIR : DATA_DIR & "/assets/utility"
--# Directory for Bundler icons
property ICONS_DIR : DATA_DIR & "/assets/icons"
--# Where color alternatives are cached
property COLOR_CACHE : DATA_DIR & "/color-cache"

(* GLOBAL VARIABLES *)

--# Where installer.sh can be downloaded from
global BASH_BUNDLET_URL
set BASH_BUNDLET_URL to my formatter("https://raw.githubusercontent.com/shawnrice/alfred-bundler/{}/bundler/bundlets/alfred.bundler.sh", BUNDLER_VERSION)

--# Bundler log file
global BUNDLER_LOGFILE
set BUNDLER_LOGFILE to my formatter((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)

(* ///
USER API
/// *)

on utility(_name, _version, _json)
	--# partial support for "optional" args in Applescript
	if my is_empty(_version) then
		set _version to "latest"
	end if
	if my is_empty(_json) then
		set _json to ""
	end if
	--# path to specific utility
	set utility to my joiner({UTILITIES_DIR, _name, _version}, "/")
	if my folder_exists(utility) = false then
		--# if utility isn't already installed
		my logger("utility", "INFO", my formatter("Utility at `{}` not found...", utility))
		set bash_bundlet to (my dirname(AS_BUNDLER)) & "bundlets/alfred.bundler.sh"
		if my file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my joiner({bash_bundlet_cmd, "utility", _name, _version, _json}, space)
			set cmd to my prepare_cmd(cmd)
			my logger("utility", "INFO", my formatter("Running shell command: `{}`...", cmd))
			set full_path to (do shell script cmd)
			return full_path
		else
			set error_msg to my logger("utility", "DEBUG", my formatter("Internal bash bundlet `{}` does not exist.", bash_bundlet))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	else
		--# if utility is already installed
		my logger("utility", "INFO", my formatter("Utility at `{}` found...", utility))
		--# read utilities invoke file
		set invoke_file to utility & "/invoke"
		if my file_exists(invoke_file) = true then
			set invoke_path to my _read_file(invoke_file)
			--# combine utility path with invoke path
			set full_path to utility & "/" & invoke_path
			return full_path
		else
			set error_msg to my logger("utility", "DEBUG", my formatter("Internal invoke file `{}` does not exist.", invoke_file))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	end if
end utility

on icon(_font, _name, _color, _alter)
	--# partial support for "optional" args in Applescript
	if my is_empty(_color) then
		set _color to "000000"
		if my is_empty(_alter) then
			set _alter to true
		end if
	end if
	if my is_empty(_alter) then
		set _alter to false
	end if
	--# path to specific icon
	set icon to my joiner({ICONS_DIR, _font, _color, _name}, "/")
	if my folder_exists(icon) = false then
		--# if icon isn't already installed
		my logger("icon", "INFO", my formatter("Icon at `{}` not found...", icon))
		set bash_bundlet to (my dirname(AS_BUNDLER)) & "bundlets/alfred.bundler.sh"
		if my file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my joiner({bash_bundlet_cmd, "icon", _font, _name, _color, _alter}, space)
			set cmd to my prepare_cmd(cmd)
			my logger("icon", "INFO", my formatter("Running shell command: `{}`...", cmd))
			set full_path to (do shell script cmd)
		else
			set error_msg to my logger("icon", "DEBUG", my formatter("Internal bash bundlet `{}` does not exist.", bash_bundlet))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	else
		--# if icon is already installed
		my logger("icon", "INFO", my formatter("Icon at `{}` found...", icon))
		return icon
	end if
end icon

(* ///
LOGGING HANDLER
/// *)

on logger(_handler, _level, _message)
	--# Ensure log file exists, with
	--# checking for scope of global var
	try
		my check_file(BUNDLER_LOGFILE)
	on error
		set BUNDLER_LOGFILE to my formatter((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)
		my check_file(BUNDLER_LOGFILE)
	end try
	delay 0.1 -- delay to ensure IO action is completed
	--# Prepare time string format %Y-%m-%d %H:%M:%S
	set log_time to "[" & (my date_formatter()) & "]"
	set formatterted_time to text items 1 thru -4 of (time string of (current date)) as string
	set error_time to "[" & formatterted_time & "]"
	--# Prepare location message
	set _location to "[bundler.scpt:" & _handler & "]"
	--# Prepare level message
	set _level to "[" & _level & "]"
	--# Generate full error message for logging
	set log_msg to (my joiner({log_time, _location, _level, _message}, space)) & (ASCII character 10)
	my write_to_file(log_msg, BUNDLER_LOGFILE, true)
	--# Generate regular error message for returning to user
	set error_msg to error_time & space & _location & space & _level & space & _message
	return error_msg
end logger

(* ///
SUB-ACTION HANDLERS
/// *)

on date_formatter()
	set {year:y, month:m, day:d} to current date
	set date_num to (y * 10000 + m * 100 + d) as string
	set formatterted_date to ((text 1 thru 4 of date_num) & "-" & (text 5 thru 6 of date_num) & "-" & (text 7 thru 8 of date_num))
	set formatterted_time to text items 1 thru -4 of (time string of (current date)) as string
	return formatterted_date & space & formatterted_time
end date_formatter

on _read_file(target_file)
	open for access POSIX file target_file
	set _contents to (read target_file)
	close access target_file
	return _contents
end _read_file

on prepare_cmd(cmd)
	set pwd to quoted form of (my pwd())
	return "cd " & pwd & "; bash " & cmd
end prepare_cmd

(* ///
IO HELPER FUNCTIONS
/// *)

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access POSIX file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

--#
on pwd()
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of (POSIX path of (path to me)) as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end pwd

on dirname(_file)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of _file as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end dirname

on check_dir(_folder)
	if not my folder_exists(_folder) then
		do shell script "mkdir -p " & (quoted form of _folder)
	end if
	return _folder
end check_dir

on check_file(_path)
	if not my file_exists(_path) then
		set _dir to dirname(_path)
		my check_dir(_dir)
		delay 0.1
		do shell script "touch " & (quoted form of _path)
	end if
end check_file

--#  handler to check if a folder exists
on folder_exists(_folder)
	if my path_exists(_folder) then
		tell application "System Events"
			return (class of (disk item _folder) is folder)
		end tell
	end if
	return false
end folder_exists

--# handler to check if a file exists
on file_exists(_file)
	if my path_exists(_file) then
		tell application "System Events"
			return (class of (disk item _file) is file)
		end tell
	end if
	return false
end file_exists

--#  handler to check if a path exists
on path_exists(_path)
	if _path is missing value or my is_empty(_path) then return false

	try
		if class of _path is alias then return true
		if _path contains ":" then
			alias _path
			return true
		else if _path contains "/" then
			POSIX file _path as alias
			return true
		else
			return false
		end if
	on error msg
		return false
	end try
end path_exists

(* ///
TEXT HELPER FUNCTIONS
/// *)

on split(str, delimiter)
	local delimiter, str, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delimiter
		set str to text items of str
		set AppleScript's text item delimiters to ASTID
		return str --> list
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't explode: " & msg number num
	end try
end split

--# format string á la Python
on formatter(str, arg)
	local ASTID, str, arg, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to "{}"
			set lst to every text item of str
			set AppleScript's text item delimiters to arg
			set str to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return str
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & msg number num
	end try
end formatter

--# removes white space surrounding a string
on trim(str)
	if class of str is not text or class of str is not string or str is missing value then return str
	if str is "" then return str
	repeat while str begins with " "
		try
			set str to items 2 thru -1 of str as text
		on error msg
			return ""
		end try
	end repeat
	repeat while str ends with " "
		try
			set str to items 1 thru -2 of str as text
		on error
			return ""
		end try
	end repeat
	return str
end trim

on joiner(pieces, delim)
	local delim, pieces, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delim
		set pieces to "" & pieces
		set AppleScript's text item delimiters to ASTID
		return pieces --> text
	on error emsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't implode: " & emsg number eNum
	end try
end joiner

(* ///
LOWER LEVEL HELPER FUNCTIONS
/// *)

--# checks if a value is empty
on is_empty(str)
	if {true, false} contains str then return false
	if str is missing value then return true
	return length of (my trim(str)) is 0
end is_empty

--TESTING!!
on test()
	set as_pwd to POSIX path of (path to me) as string
	set pwd to quoted form of my dirname(as_pwd)
	set cmd to quoted form of "/Users/smargheim/Documents/DEVELOPMENT/GitHub/alfred-bundler/bundler/bundlets/TEST.sh"
	set sh_pwd to do shell script "cd " & pwd & "; bash " & cmd
	return "Applescript PWD: " & as_pwd & return & "Shell PWD: " & sh_pwd
end test

(* GLOBAL PROPERTIES

&& $? for bash status codes

*)
property BUNDLER_VERSION : "devel"
--# Bundler paths
property _home : POSIX path of (path to "cusr" as text)
property BUNDLER_DIR : (_home) & "Library/Application Support/Alfred 2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
property DATA_DIR : BUNDLER_DIR & "/data"
property CACHE_DIR : (_home) & "Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
--# Main Applescript Bundler
property AS_BUNDLER : BUNDLER_DIR & "/bundler/AlfredBundler.scpt"
--# Root directory under which workflow-specific applescript libraries are installed
property APPLESCRIPT_DIR : DATA_DIR & "/assets/applescript"
--# Root directory under which Bundler utilities are installed
property UTILITIES_DIR : DATA_DIR & "/assets/utility"
--# Directory for Bundler icons
property ICONS_DIR : DATA_DIR & "/assets/icons"
--# Where color alternatives are cached
property COLOR_CACHE : DATA_DIR & "/color-cache"

(* GLOBAL VARIABLES *)

--# Where installer.sh can be downloaded from
global BASH_BUNDLET_URL
set BASH_BUNDLET_URL to my formatter("https://raw.githubusercontent.com/shawnrice/alfred-bundler/{}/bundler/bundlets/alfred.bundler.sh", BUNDLER_VERSION)

--# Bundler log file
global BUNDLER_LOGFILE
set BUNDLER_LOGFILE to my formatter((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)

(* ///
USER API
/// *)

on utility(_name, _version, _json)
	--# partial support for "optional" args in Applescript
	if my is_empty(_version) then
		set _version to "latest"
	end if
	if my is_empty(_json) then
		set _json to ""
	end if
	--# path to specific utility
	set utility to my joiner({UTILITIES_DIR, _name, _version}, "/")
	if my folder_exists(utility) = false then
		--# if utility isn't already installed
		my logger("utility", "INFO", my formatter("Utility at `{}` not found...", utility))
		set bash_bundlet to (my dirname(AS_BUNDLER)) & "bundlets/alfred.bundler.sh"
		if my file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my joiner({bash_bundlet_cmd, "utility", _name, _version, _json}, space)
			set cmd to my prepare_cmd(cmd)
			my logger("utility", "INFO", my formatter("Running shell command: `{}`...", cmd))
			set full_path to (do shell script cmd)
			return full_path
		else
			set error_msg to my logger("utility", "DEBUG", my formatter("Internal bash bundlet `{}` does not exist.", bash_bundlet))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	else
		--# if utility is already installed
		my logger("utility", "INFO", my formatter("Utility at `{}` found...", utility))
		--# read utilities invoke file
		set invoke_file to utility & "/invoke"
		if my file_exists(invoke_file) = true then
			set invoke_path to my read_file(invoke_file)
			--# combine utility path with invoke path
			set full_path to utility & "/" & invoke_path
			return full_path
		else
			set error_msg to my logger("utility", "DEBUG", my formatter("Internal invoke file `{}` does not exist.", invoke_file))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	end if
end utility

on icon(_font, _name, _color, _alter)
	--# partial support for "optional" args in Applescript
	if my is_empty(_color) then
		set _color to "000000"
		if my is_empty(_alter) then
			set _alter to true
		end if
	end if
	if my is_empty(_alter) then
		set _alter to false
	end if
	--# path to specific icon
	set icon to my joiner({ICONS_DIR, _font, _color, _name}, "/")
	if my folder_exists(icon) = false then
		--# if icon isn't already installed
		my logger("icon", "INFO", my formatter("Icon at `{}` not found...", icon))
		set bash_bundlet to (my dirname(AS_BUNDLER)) & "bundlets/alfred.bundler.sh"
		if my file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my joiner({bash_bundlet_cmd, "icon", _font, _name, _color, _alter}, space)
			set cmd to my prepare_cmd(cmd)
			my logger("icon", "INFO", my formatter("Running shell command: `{}`...", cmd))
			set full_path to (do shell script cmd)
		else
			set error_msg to my logger("icon", "DEBUG", my formatter("Internal bash bundlet `{}` does not exist.", bash_bundlet))
			error error_msg number 1
			--##TODO: need a stable error number schema
		end if
	else
		--# if icon is already installed
		my logger("icon", "INFO", my formatter("Icon at `{}` found...", icon))
		return icon
	end if
end icon

(* ///
LOGGING HANDLER
/// *)

on logger(_handler, _level, _message)
	--# Ensure log file exists, with
	--# checking for scope of global var
	try
		my check_file(BUNDLER_LOGFILE)
	on error
		set BUNDLER_LOGFILE to my formatter((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)
		my check_file(BUNDLER_LOGFILE)
	end try
	delay 0.1 -- delay to ensure IO action is completed
	--# Prepare time string format %Y-%m-%d %H:%M:%S
	set log_time to "[" & (my date_formatter()) & "]"
	set formatterted_time to text items 1 thru -4 of (time string of (current date)) as string
	set error_time to "[" & formatterted_time & "]"
	--# Prepare location message
	set _location to "[bundler.scpt:" & _handler & "]"
	--# Prepare level message
	set _level to "[" & _level & "]"
	--# Generate full error message for logging
	set log_msg to (my joiner({log_time, _location, _level, _message}, space)) & (ASCII character 10)
	my write_to_file(log_msg, BUNDLER_LOGFILE, true)
	--# Generate regular error message for returning to user
	set error_msg to error_time & space & _location & space & _level & space & _message
	return error_msg
end logger

(* ///
SUB-ACTION HANDLERS
/// *)

on date_formatter()
	set {year:y, month:m, day:d} to current date
	set date_num to (y * 10000 + m * 100 + d) as string
	set formatterted_date to ((text 1 thru 4 of date_num) & "-" & (text 5 thru 6 of date_num) & "-" & (text 7 thru 8 of date_num))
	set formatterted_time to text items 1 thru -4 of (time string of (current date)) as string
	return formatterted_date & space & formatterted_time
end date_formatter

on read_file(target_file)
	open for access POSIX file target_file
	set _contents to (read target_file)
	close access target_file
	return _contents
end read_file

on prepare_cmd(cmd)
	set pwd to quoted form of (my _pwd())
	return "cd " & pwd & "; bash " & cmd
end prepare_cmd

(* ///
IO HELPER FUNCTIONS
/// *)

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access POSIX file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

--#
on pwd()
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of (POSIX path of (path to me)) as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end pwd

on dirname(_file)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of _file as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end dirname

on check_dir(_folder)
	if not my folder_exists(_folder) then
		do shell script "mkdir -p " & (quoted form of _folder)
	end if
	return _folder
end check_dir

on check_file(_path)
	if not my file_exists(_path) then
		set _dir to dirname(_path)
		my check_dir(_dir)
		delay 0.1
		do shell script "touch " & (quoted form of _path)
	end if
end check_file

--#  handler to check if a folder exists
on folder_exists(_folder)
	if my path_exists(_folder) then
		tell application "System Events"
			return (class of (disk item _folder) is folder)
		end tell
	end if
	return false
end folder_exists

--# handler to check if a file exists
on file_exists(_file)
	if my path_exists(_file) then
		tell application "System Events"
			return (class of (disk item _file) is file)
		end tell
	end if
	return false
end file_exists

--#  handler to check if a path exists
on path_exists(_path)
	if _path is missing value or my is_empty(_path) then return false

	try
		if class of _path is alias then return true
		if _path contains ":" then
			alias _path
			return true
		else if _path contains "/" then
			POSIX file _path as alias
			return true
		else
			return false
		end if
	on error msg
		return false
	end try
end path_exists

(* ///
TEXT HELPER FUNCTIONS
/// *)

on split(str, delimiter)
	local delimiter, str, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delimiter
		set str to text items of str
		set AppleScript's text item delimiters to ASTID
		return str --> list
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't explode: " & msg number num
	end try
end split

--# format string á la Python
on formatter(str, arg)
	local ASTID, str, arg, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to "{}"
			set lst to every text item of str
			set AppleScript's text item delimiters to arg
			set str to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return str
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & msg number num
	end try
end formatter

--# removes white space surrounding a string
on trim(str)
	if class of str is not text or class of str is not string or str is missing value then return str
	if str is "" then return str
	repeat while str begins with " "
		try
			set str to items 2 thru -1 of str as text
		on error msg
			return ""
		end try
	end repeat
	repeat while str ends with " "
		try
			set str to items 1 thru -2 of str as text
		on error
			return ""
		end try
	end repeat
	return str
end trim

on joiner(pieces, delim)
	local delim, pieces, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delim
		set pieces to "" & pieces
		set AppleScript's text item delimiters to ASTID
		return pieces --> text
	on error emsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't implode: " & emsg number eNum
	end try
end joiner

(* ///
LOWER LEVEL HELPER FUNCTIONS
/// *)

--# checks if a value is empty
on is_empty(str)
	if {true, false} contains str then return false
	if str is missing value then return true
	return length of (my trim(str)) is 0
end is_empty

--TESTING!!
on test()
	set as_pwd to POSIX path of (path to me) as string
	set pwd to quoted form of my dirname(as_pwd)
	set cmd to quoted form of "/Users/smargheim/Documents/DEVELOPMENT/GitHub/alfred-bundler/bundler/bundlets/TEST.sh"
	set sh_pwd to do shell script "cd " & pwd & "; bash " & cmd
	return "Applescript PWD: " & as_pwd & return & "Shell PWD: " & sh_pwd
end test


added Escape text for use as FM Calc

added Escape text for use as FM Calc

Scripts/fmClip - Escape text for use as FM Calc.applescript


Make sure we're checking the artwork count of the current track

--HG--
extra : convert_revision : svn%3A99687598-2e92-11dd-8019-fe7b9d601d1b/trunk%40584

FasdUAS 1.101.10
k
l
Q

O
k

r

m
fsck
o0returnvaluereturnValue
r
1

pPlS
o0astateaState
Z
=
o0astateaState
m
ePlSkPSP
k
r!"
!1

pTrk
"o0atrackaTrack #$
#r$%&
%n"'(
'1 "

pnam
(1

pPla
&o0alibraryaLibrary$)*
)r%*+,
+n%(-.
-1&(

pDID
.o%&0atrackaTrack
,o0atrackidaTrackID*/0
/r+012
1n+.34
31,.

pnam
4o+,0atrackaTrack
2o0
atrackname
aTrackName056
5r1678
7n149:
9124

pTim
:o120atrackaTrack
8o0atracklengthaTracklength6;<
;r7@=>
=n7<?@
?18<

pAlb
@o780atrackaTrack
>o0atrackalbumaTrackAlbum<AB
ArAJCD
CnAFEF
E1BF

pArt
FoAB0atrackaTrack
Do0atrackartistaTrackArtistBGH
GrKTIJ
InKPKL
K1LP

pAnt
LoKL0atrackaTrack
Jo&0atrackcompilationaTrackCompilationHMN
MrU^OP
OnUZQR
Q1VZ

pRte
RoUV0atrackaTrack
Po0atrackratingaTrackRatingNST
Sr_fUV
Um_b

null
Vo0
atrackartwork
aTrackArtworkTWX
WZgYZ
Y@gr[\
[lgp]
]Igp^
.corecnte********
^ngl_`
_mhl

cArt
`ogh0atrackaTrack
\mpq
Zruab
anucd
c1{

pPCT
dnu{ef
e4v{g

cArt
gmyz
fouv0atrackaTrack
bo0
atrackartwork
aTrackArtworkXh
hrij
iJkklm
lo0atrackidaTrackIDmno
no0
atrackname
aTrackNameopq
po0atracklengthaTracklengthqrs
ro0atrackartistaTrackArtiststu
to0atrackalbumaTrackAlbumuvw
vo&0atrackcompilationaTrackCompilationwxy
xo0atrackratingaTrackRatingyz{
zo0
atrackartwork
aTrackArtwork{|
|o0alibraryaLibrary
jo0returnvaluereturnValue}~
}=
o0astateaState
m
ePlSkPSp~
r
mpaused
o0returnvaluereturnValue
r
m
stopped
o0returnvaluereturnValue
mnull
iTunes.app07@ j)h( `hookalis8ShireOH+
iTunes.appxͼG	 ApplicationsOShire:Applications:iTunes.app
iTunes.appShireApplications/iTunes.app/
	R
.ascrerr ********

r
m
fsck
o0returnvaluereturnValue
l
L
o0returnvaluereturnValue
l
.aevtoappnull****0returnvaluereturnValue0astateaState0atrackaTrack0alibraryaLibrary0atrackidaTrackID0
atrackname
aTrackName0atracklengthaTracklength0atrackalbumaTrackAlbum0atrackartistaTrackArtist&0atrackcompilationaTrackCompilation0atrackratingaTrackRating0
atrackartwork
aTrackArtwork
.aevtoappnull****
k$~}|{zy0returnvaluereturnValue

pPlS0astateaState
ePlSkPSP

pTrk0atrackaTrack

pPla

pnam0alibraryaLibrary

pDID0atrackidaTrackID0
atrackname
aTrackName

pTim0atracklengthaTracklength

pAlb0atrackalbumaTrackAlbum

pArt0atrackartistaTrackArtist

pAnt&0atrackcompilationaTrackCompilation

pRte0atrackratingaTrackRating

null0
atrackartwork
aTrackArtwork

cArt
~.corecnte********
}
pPCT|
{ePlSkPSpzyEO*,EO*,EO*,,EO,EO,EO,EOa,E`Oa,E`Oa,E`Oa,E`OaE`Oa,jkak/a,E`YhO_____avEYa
aEYa EUWX!"a#EOxx		wvuw	Fett's 'Vette3:22MC Chris
vboovfalsudl
PICTk,,HH,,
,,k6@@,,Vjpegappl,,HHjPhoto - JPEGJFIF,,CC,,"
P
!"#19TV2At4Q$%38BYax')FUXqw*Q!12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bE3ʭY(KLZrXOq2)|
husӴ+u)fX\F;keUy̝BêЎTԉlt@A!';Maj[(](FCh)9pQ*7v_DO9Pq#M88888888888888888888888|
,,,,(aQuickTime and a(FPhoto - JPEG decompressor(<are needed to see this picture.Library
ePlSkPSPtsrqponml
n
cSrcm&
lkfrmID
q
cLiPp"
okfrmID
t
cFlTs=
rkfrmID
boovfalsdascrޭ

FasdUAS 1.101.10
k
l
Q

O
k

r

m
fsck
o0returnvaluereturnValue
r
1

pPlS
o0astateaState
Z
=
o0astateaState
m
ePlSkPSP
k
r!"
!1

pTrk
"o0atrackaTrack #$
#r$%&
%n"'(
'1 "

pnam
(1

pPla
&o0alibraryaLibrary$)*
)r%*+,
+n%(-.
-1&(

pDID
.o%&0atrackaTrack
,o0atrackidaTrackID*/0
/r+012
1n+.34
31,.

pnam
4o+,0atrackaTrack
2o0
atrackname
aTrackName056
5r1678
7n149:
9124

pTim
:o120atrackaTrack
8o0atracklengthaTracklength6;<
;r7@=>
=n7<?@
?18<

pAlb
@o780atrackaTrack
>o0atrackalbumaTrackAlbum<AB
ArAJCD
CnAFEF
E1BF

pArt
FoAB0atrackaTrack
Do0atrackartistaTrackArtistBGH
GrKTIJ
InKPKL
K1LP

pAnt
LoKL0atrackaTrack
Jo&0atrackcompilationaTrackCompilationHMN
MrU^OP
OnUZQR
Q1VZ

pRte
RoUV0atrackaTrack
Po0atrackratingaTrackRatingNST
Sr_fUV
Um_b

null
Vo0
atrackartwork
aTrackArtworkTWX
WZgYZ
Y@gp[\
[Ign]
.corecnte********
]mgj

cArt
\mno
Zrs^_
^ns}`a
`1y}

pPCT
ansybc
b4tyd

cArt
dmwx
cost0atrackaTrack
_o0
atrackartwork
aTrackArtworkXe
erfg
fJhhij
io0atrackidaTrackIDjkl
ko0
atrackname
aTrackNamelmn
mo0atracklengthaTracklengthnop
oo0atrackartistaTrackArtistpqr
qo0atrackalbumaTrackAlbumrst
so&0atrackcompilationaTrackCompilationtuv
uo0atrackratingaTrackRatingvwx
wo0
atrackartwork
aTrackArtworkxy
yo0alibraryaLibrary
go0returnvaluereturnValuez{
z=|}
|o0astateaState
}m
ePlSkPSp{~
~r
mpaused
o0returnvaluereturnValue
r
m
stopped
o0returnvaluereturnValue
mnull
iTunes.app0L7 $)4(K @hookalisLMacintosh HDFwH+
iTunes.app@T	 ApplicationsF$Macintosh HD:Applications:iTunes.app
iTunes.appMacintosh HDApplications/iTunes.app/
	R
.ascrerr ********

r
m
fsck
o0returnvaluereturnValue
l
L
o0returnvaluereturnValue
l
.aevtoappnull****0returnvaluereturnValue0astateaState0atrackaTrack0alibraryaLibrary0atrackidaTrackID0
atrackname
aTrackName0atracklengthaTracklength0atrackalbumaTrackAlbum0atrackartistaTrackArtist&0atrackcompilationaTrackCompilation0atrackratingaTrackRating0
atrackartwork
aTrackArtwork
.aevtoappnull****
k$~}|{z0returnvaluereturnValue

pPlS0astateaState
ePlSkPSP

pTrk0atrackaTrack

pPla

pnam0alibraryaLibrary

pDID0atrackidaTrackID0
atrackname
aTrackName

pTim0atracklengthaTracklength

pAlb0atrackalbumaTrackAlbum

pArt0atrackartistaTrackArtist

pAnt&0atrackcompilationaTrackCompilation

pRte0atrackratingaTrackRating

null0
atrackartwork
aTrackArtwork

cArt
.corecnte********
~
pPCT}
|ePlSkPSp{zEO*,EO*,EO*,,EO,EO,EO,EOa,E`Oa,E`Oa,E`Oa,E`OaE`Oajkak/a,E`YhO_____avEYa
aEYa EUWX!"a#EOyy		xwvuxH(Random Drinking Song3:32
wboovfalsv<
u
nullParty Shuffle
ePlSkPSPtsrqponml
n
cSrcm#
lkfrmID
q
cUsPpE
okfrmID
t
cFlTs4.
rkfrmID  H
boovfals<

nullascr
ޭ


addNearTop for fmGUI_ManageLayouts_Layout_CreateOrUpdate

-- fmGUI_ManageLayouts_Layout_CreateOrUpdate({layoutName:null, oldLayoutName:null, doNotChangeExisting:false, baseTableName:null, layoutParentFolder:"", includeInLayoutMenus:0, menuSet:null, formViewEnabled:1, listViewEnabled:1, tableViewEnabled:1, defaultView:"Form View", scriptTriggers:{}})
-- Daniel A. Shockley, NYHTC
-- Create/Update a layout.

(*
HISTORY:
	2020-03-04 ( dshockley ): Minor fixes. Proper calls to fmGUI_CheckboxSet and fmGUI_PopupSet. 1625: Added support for addNearTop.
	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
*)

property ScriptName : "fmGUI_ManageLayouts_Layout_CreateOrUpdate"
property debugMode : true

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

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

on fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)
	-- version 2020-03-04-1625

	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:{}, addNearTop:false}

	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({objRef:inludeInMenuButton, objValue:includeInLayoutMenus of layoutOptions})
					if menuSet of layoutOptions is not null then fmGUI_PopupSet({objRef: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({objRef:formCheckbox, objValue:formViewEnabled of layoutOptions})
					if listViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet({objRef:listCheckbox, objValue:listViewEnabled of layoutOptions})
					if tableViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet({objRef:tableCheckbox, objValue:tableViewEnabled of layoutOptions})
					if defaultView of layoutOptions is not null then fmGUI_PopupSet({objRef: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({folderName: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({objRef:checkboxRef, objValue:1})

				end if
			else if addNearTop of layoutOptions then
				-- select the 1st row/layout so that this new one gets added just below it, instead of at bottom of whole list:
				tell application "System Events"
					tell application process "FileMaker Pro Advanced"
						select row 1 of outline 1 of scroll area 1 of manageLayoutsWindow
					end tell
				end tell

			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: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(processName, consoleMsg)
	tell application "htcLib" to logConsole(processName, consoleMsg)
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, oldLayoutName:null, doNotChangeExisting:false, baseTableName:null, layoutParentFolder:"", includeInLayoutMenus:0, menuSet:null, formViewEnabled:1, listViewEnabled:1, tableViewEnabled:1, defaultView:"Form View", scriptTriggers:{}})
-- Daniel A. Shockley, NYHTC
-- Create/Update a layout.

(*
HISTORY:
	2020-03-04 ( dshockley ): Minor fixes. Proper calls to fmGUI_CheckboxSet and fmGUI_PopupSet.
	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
*)

property ScriptName : "fmGUI_ManageLayouts_Layout_CreateOrUpdate"
property debugMode : true

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

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

on fmGUI_ManageLayouts_Layout_CreateOrUpdate(layoutOptions)
	-- version 2020-03-04-1543

	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({objRef:inludeInMenuButton, objValue:includeInLayoutMenus of layoutOptions})
					if menuSet of layoutOptions is not null then fmGUI_PopupSet({objRef: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({objRef:formCheckbox, objValue:formViewEnabled of layoutOptions})
					if listViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet({objRef:listCheckbox, objValue:listViewEnabled of layoutOptions})
					if tableViewEnabled of layoutOptions is not null then fmGUI_CheckboxSet({objRef:tableCheckbox, objValue:tableViewEnabled of layoutOptions})
					if defaultView of layoutOptions is not null then fmGUI_PopupSet({objRef: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({folderName: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({objRef:checkboxRef, objValue: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: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(processName, consoleMsg)
	tell application "htcLib" to logConsole(processName, consoleMsg)
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


removed tell htcLib code from 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
			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

-- 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 tell application "htcLib" to 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
			clickObjFromHtcLib(buttonRef)
			tell application "htcLib" to 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
			tell application "htcLib" to 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


added fmClip - Button Info from Clipboard

Scripts/fmClip - Button Info from Clipboard.applescript