checkMyMemory

I often find that the functions performed by my scripts can get pretty memory-intensive so I developed this subroutine which I use as a library to check the parent script’s minimum partition size and warn the user if the memory is set too low. It includes the option to abort the script and open the information window for the script, ignore and continue or disable the warning. The routine uses the “application file of process scriptName” so the Finder finds the script no matter the location.

OS version: MacOS

-- You will need to define these variables and properties

-- sugSize = Minimum Suggested Partition Size
-- memIgnore = a property to allow user to disable memory warning
-- runScript = enclosing "if" statement to tell script whether or not to run pending user response to this warning

-- The routine

on checkMyMemory(scriptName, sugSize)
	if memIgnore != "Ignore" then
		tell application "Finder"
			activate
			set thisApp to application file of process scriptName as string
			set minSize to (minimum size of application file thisApp) div 1024
			if minSize < sugSize then
				beep
				set memAnswer to button returned of (display dialog scriptName & "'s minimum memory is set to " & minSize & " but should to be at least " & sugSize & "." buttons {"Don't Show Again", "Open Info", "Continue"} with icon 2) as string
				if memAnswer = "Open Info" then
					set runScript to false
					open information window of file thisApp
				else
					if memAnswer = "Continue" then
						set runScript to true
					else
						set runScript to true
						set memIgnore to "Ignore"
					end if
				end if
			else
				set runScript to true
			end if
		end tell
	else
		set runScript to true
	end if
	return runScript
end checkMyMemory