How to test for which Mac is being used

I would like to create a script which prompts me to choose a folder and then open 4 finder windows each which contains a different sub-folder of the chosen folder.

But I would like to test first which of two Macs I am using. The purpose of the test will result in the script opening the windows at a different size.

I do not know how to test for the Mac I am using and incorporate the result of the test into an If statement.

The code I have written to open the 4 Finder windows is as follows:

set the target_item to path to home folder as string

set the target_item to target_item & "vwdata:"

set the target_item to target_item & "notary:"

set the target_item to target_item & "2020"

set the target_item to target_item as alias

set the source_folder to choose folder with prompt "pick the notary folder you wish to see" default location alias target_item

set source_folder to source_folder as text

set v_id to source_folder & "id:"
set v_complete to source_folder & "notarised_signed documents:"
set v_invoice to source_folder & "invoice:"
set v_legalisation to source_folder & "legalisation:"


tell application "Finder"
	
	close every window
	
	open folder v_id
	tell the front Finder window
		set the sidebar width to 135
		set the toolbar visible to true
		set the current view to list view
		set the bounds to {0, 25, 720, 450}
	end tell
	
	
	open folder v_complete
	tell the front Finder window
		set the sidebar width to 135
		set the toolbar visible to true
		set the current view to list view
		set the bounds to {0, 451, 720, 900}
	end tell
	
	open folder v_invoice
	tell the front Finder window
		set the sidebar width to 135
		set the toolbar visible to true
		set the current view to list view
		set the bounds to {721, 451, 1440, 900}
	end tell
	
	
	open folder v_legalisation
	tell the front Finder window
		set the sidebar width to 135
		set the toolbar visible to true
		set the current view to list view
		set the bounds to {721, 25, 1440, 450}
	end tell
	
	
end tell

The above code would be duplicated with different bounds statement for the other Mac.

Any help would be gratefully received.

Simple, as this


set modelIdentifier to (do shell script "/usr/sbin/system_profiler SPHardwareDataType | sed -En '/Model Identifier:/ s/^[^:]+: *//p'")

Maybe, you need system version instead of Mac model identifier for your task:


set systemVersion to system version of (system info)

The question is a simple one but the answer may vary depending on how you can distinguish one computer from the other. One of KniazidisR’s suggestions will probably do the job fine. If not, I’d run system info in script editor and look at the output in the result pane to decide if one will do the job. For example, computer name might work:

set computerName to computer name of (system info)

BTW, I ran the system_profiler solution in Script Geek and it took 200 milliseconds to run. I then tested the system info solution and it took 2 milliseconds to run. So, if it does the job, system info would probably be best.

Perhaps there’s a reason for writing the above code in this manner but it seems unnecessarily long. An alternative to consider:

set thetarget_item to ((path to home folder) as text) & "vwdata:notary:2020:"

If you’re using different bounds, it suggests the Macs have different size screens. You could therefore check the desktop size, and base your decision on that:

tell application id "com.apple.finder" -- Finder
	set {theLeft, theTop, theRight, theBottom} to bounds of container window of desktop
end tell

Better to use:

set thetarget_item to (path to home folder as text) & "vwdata:notary:2020:"

That way as is a parameter, avoiding the need for a coercion.

Thanks Shane. I didn’t understand this at first but then looked at the Standard Additions dictionary:

I tested this with Script Geek and it took 1 millisecond. It’s hard to do better than that.