Beginner Question: Referencing Project Resources from AppleScript

Forgive my ignorance… I’m very new to applescript and xcode.

I’m creating a utility which uses ‘certtool’ to insert a .cer file, which I would like to include as a project ‘resource’. I have already included the .cer file as a project resource; however, I have no clue as to how you would reference the .cer file from the applescript. Using the example below, I would like to replace the CertPath variable with the actual path to the .cer file from within the project. :confused: Is there a way to do this? Any help is greatly appreciated… I’m using xcode 2.2.1


--[ Install Cert File ]-------------------------------------
on install_cert_file()

set CertPath to ???

	try
		do shell script "certtool i " & CertPath & " k=/System/Library/Keychains/X509Anchors d v" with administrator privileges
	end try
	
end install_cert_file

Try one of these:

-- This would work for a Studio app as well as a app bundle from Script Editor
set CertPath to POSIX path of ((path to me as Unicode text) & "Contents:Resources:rmmiles.cer")

-- This also works for both (as above), but only on OS X v10.4+
set CertPath to POSIX path of (path to resource "rmmiles.cer")

-- This only works for Studio apps
set CertPath to (resource path of main bundle) & "/rmmiles.cer"

You’ll probably want to quote the path before using it:

do shell script "/usr/bin/certtool i " & (quoted form of CertPath) & " k=/System/Library/Keychains/X509Anchors d v" with administrator privileges

See also: bundle class

Bruce:

Wow, thanks for the quick response… works like a charm. :slight_smile: