script moves folder from resources folder

I have a NIB file with custom fonts in it. SO I am checking “on open” that the user has the fonts installed on there system. If they don’t I would like to move the folder of fonts “appFonts” from my resources folder to their user/library/fonts folder. Problem is is that I don’t know how to get to my resources folder and address the “appFonts” folder

Any ideas?

Thanks

Hi,

path to me is the alias of the application itself.
The HFS path string is

set appFonts to ((path to me as text) & "Contents:Resources:appFonts:")

Thanks for the quick reply. I tried that and I am getting a error.

This is what I am trying to do

tell application "Finder"
			try
				set x to folder "Create Demo Report Fonts" of fontsdir
			on error
				set appFonts to ((path to me as text) & "Contents:Resources:appFonts:")
				move appFonts to fontsdir
			end try
		end tell

What simple step am I missing?

the keyword folder


tell application "Finder"
	try
		set x to folder "Create Demo Report Fonts" of fontsdir
	on error
		set appFonts to ((path to me as text) & "Contents:Resources:appFonts:")
		duplicate folder appFonts to fontsdir
	end try
end tell

I recommend to use duplicate instead of move :wink:

Still getting a error.

Not sure what is going on here.

I’ve always used:

set thePath to resource path of main bundle & "/appFonts/"

Similarly, I always use Terminal to handle files. It’s easier than the AppleScript “open for access” nonsense:

do shell script ("cp -r " & thePath & " ~/Library/Fonts/")

Also, this is a really good idea. I seem to run into font problems a lot. Let me know if this works! :wink:

-SuperScripter

I’m not sure, but I think working with the terminal requires a "" before every space in a path OR you have to use quoted form of:


do shell script ("cp -r " & quoted form of thePath & " ~/Library/Fonts/")

You’re absolutely right. I completely overlooked this. But, to be technical, in AppleScript, you must use “//” before a space:

AppleScript, like many languages, uses “/” as an “ignore syntax” character. So, "/ " would be “ignore the space”. However, "// " is “ignore the slash before the space”. I think I’m being kinda unclear here, but I can’t think of a better way to explain it.

But, especially for new people to AppleScript, keep this in mind. It took me a while to figure out, and I think it’s a really valuable piece of information.

Also, I tried it in plain AppleScript (no Studio), and “quoted form of” didn’t seem to help the problem… :frowning:

-SuperScripter

quoted form of is the most reliable way to escape a path

btw: the escape character is backslash, not slash