On Mac, how to give a compiled program a new icon?

BlitzMax Forums/BlitzMax Programming/On Mac, how to give a compiled program a new icon?

Sokurah(Posted 2011) [#1]
I know - "not again"...but I've spent ages looking through the forum to find out how, and I've found a lot of info - but I can't seem to find a usable solution (could all that old info be for older versions of BlitzMax?).

Either people are told to "look at the package contents" and put the icns file into the right folder and then edit the plist file, but I can't see the package contents - I just don't have that option after compiling.

Sometimes people are told that they can just copy it "from the file info area of the icon, to the executable's file into", but that doesn't work either.

Can someone point me in the right direction?


ima747(Posted 2011) [#2]
There's the right way, the quick way, and the right-only-better-because-it's-automatic-but-as-a-result-annoying-to-set-up... way

The quick way:
Copy the icon graphic (the picture itself, copy it from your photo editing program)
Get info on your application
Click the icon graphic at the top (it should get a glowing ring around it to tell you it's selected)
Paste. your graphic should now be the icon.
This is bad because it's just the icon that's show, it's not the actual icon for the program. It could be lost under certain conditions. Additionally if someone selects the icon in the get info window and presses delete it goes *poof*

The right way:
create an icon bundle (.icns file) in Icon Composer (in /Developer/Applications/Utilites if you've installed XCode on your main drive...). You can drag the image file into the icon areas to have it generate the levels for you (it likes to complain about transparency but it does a good job so just ignore it). Or again copy/paste the graphic itself.
*RIGHT* click on your application (or control click if you're using an input device with 1 button) to get the popup menu of stuff you can do to it, and select "Show Package Contents". This will open a new window showing you the inside of your program (apps on a mac are actually just folders...)
You will see a Contents directory, and in that a few other things. You're looking for "Resources" and in there you're looking for the .icns file.
Replace the existing icns file with the one you made in Icon Composer (exact same name...)
Close the window, your icon might not update immediately (because the OS caches icons since it doesn't expect them to change often...) to force it to update you can move it to another folder then copy it back (this makes the OS go "OOO! a new application! let's take a look at it's resources.)
Alternatively to replacing the icon file you can modify the Info.plist in the application's contents to point to an icon file with a different name etc...

The better right way.
Not sure if the default bmk for blitzmax supports post scripts or not, but Brucy's BMK NG (check his forum here for details) does. With it you can make a post.bmk script that will automatically be run whenever you build your program. With that you can have it automatically replace/modify/etc. your contents, including copying in a new icon file, or even a custom Info.plist (very handy for getting actual version info and copywrite stuff in place, and you have to tweak the plist if you plan on going to the mac store to meet it's submission requirements...)
Here's an example post.bmk
# MacOS post build script
#
#
@define doPostInstall

	# only interested for Mac platform
	
	if bmk.Platform() == "macos" then
		
		#replace icon
		sys.CopyFile(%buildpath% .. "/Bin/icon.icns", %exepath% .. "/../Resources/" .. %outfile% .. ".icns")

		#replace info.plist
		sys.CopyFile(%buildpath% .. "/Bin/info.plist", %exepath% .. "/../info.plist")

	end

@end

# run the post install
doPostInstall

This replaces the info.plist in the application with one found at <builddirectory>/Bin/info.plist, it also replaces the icon file with one found at <builddirectory>/Bin/icon.icns


Sokurah(Posted 2011) [#3]
Thanks, I'd like to do it right right way, but...

*RIGHT* click on your application (or control click if you're using an input device with 1 button) to get the popup menu of stuff you can do to it, and select "Show Package Contents". This will open a new window showing you the inside of your program (apps on a mac are actually just folders...)
You will see a Contents directory, and in that a few other things. You're looking for "Resources" and in there you're looking for the .icns file.


...like I said; "I don't have that 'Show Package Contents' option".
(I do get it when I compile something with GLBasic, but not BlitzMax).




Brucey(Posted 2011) [#4]
I don't have that 'Show Package Contents' option

You need to build a GUI App. (check the appropriate menu option in the IDE)

This creates the app bundle folder structure.


John G(Posted 2011) [#5]
Been using the "the quick way" for years to minimize heartburn.


ima747(Posted 2011) [#6]
What brucey said, you're building non GUI apps, those are executables that on a mac will run via the terminal actually (though that doesn't mean they can't access the graphics and GUI systems, just that that have a NON gui existence as well...). As a result they are just raw binaries, not actual mac "Applications" (which as mentioned above are folder structures that contain the binary among other things).

I hope someday the maxide changes this to be a little more self explanatory, but for now everyone's gotta figure out what that toggle does sooner or later :0)


Sokurah(Posted 2011) [#7]
Aha, that makes sense - and also explains why I get that damn Terminal window - which was supposed to be a followup question. LOL.
...I guess building GUI apps is the way to go then. ;)

A couple of more (perhaps) related questions:

I've had to remove all code to run my games in windowed mode, because when they start in a window they don't react to any keypresses. Is that because I've been building them non-GUI?

I've been using an older version of BM for building my current builds - as I've just been fooling around and wasn't ready to release anything for OSX anyway, but that has now changed - I've taken the plunge, so I updated to 1.41 cos I thought it'd be best to run the latest version, but now my games that ran a steady 60 fps now run amok with 600-800 fps. Huh, what changed? There's no problem with the Windows versions.

As you can probably tell I'm new to this Mac gubbins - I'm more of a Windows person, but I've bought a Mac (a good while back but practically not used it at all) so I'm about to enter a learning process here, so there will probably be more questions. Have patience with me. :)


Brucey(Posted 2011) [#8]
I prefer "the better right way", because it doesn't require me to do anything.

So... I'm lazy and hate repetition!


Brucey(Posted 2011) [#9]
when they start in a window they don't react to any keypresses

Yep... you get a different interactive framework when you are wrapped up inside an app bundle.

now my games that ran a steady 60 fps now run amok with 600-800 fps

There may have been a change to the way it syncs on Flip.
Try Flip 1, Flip 0, or Flip -1


ima747(Posted 2011) [#10]
To backup what brucey said, I use the lazy man's way as well ;0)

Also, your flip code was probably previously sycing with the screen refresh (likely 60hz on an LCD) and that was throttling your game to 60fps. With the flip not syncing it's free to redraw as fast as it likes (say 10x faster as you're seeing...). You can force it to sync, but remember that if someone's not running at the same refresh rate (say they have a weird LCD that prefers to claim 58hz, or a CRT that goes at 96 no matter what...) it's going to affect the speed of your game. I would strongly recommend that you put in some form of throttle control (I tend to use a tweening method, search the forum, there's plenty of threads on this). This will let you run you game even smoother than 60fps on fast machines (oooo pretty) and will keep it chugging along normally on slow or spotty machines, just sacrificing fps (even if it drops to 30fps it should still be playable quite nicely rather than run at half speed...).

FYI you probably want to build GUI on windows as well (it keeps the command prompt window from coming up and potentially eating input like you're seeing...). Really wish maxide made it clearer what that toggle does...


Sokurah(Posted 2011) [#11]
There may have been a change to the way it syncs on Flip.
Try Flip 1, Flip 0, or Flip -1

I'd already tried all thee and the result was the same.

...on the positive side some of my games are so hard anyway, that people may not even notice they're running more than 10 times faster. :-D

I'll release these games using the older version of BM for now, but I'll look into tweening for future releases. ;-)

I've learned a lot today. Thanks guys.


Space Fractal(Posted 2011) [#12]
hey, you even asked me to done. As I PM you (in a another forum), this is why I normally use system timers rather than using flup to sync, since I never have trust them 100%

One of my frontend only ran at 30fps, which is another proff why I used system timer to sync with.

Howover your games seen run great now, those binany you sent to me on mac. They did not run insane fast and such thing. Its did fell correct.


Sokurah(Posted 2011) [#13]
hey, you even asked me to done. As I PM you (in a another forum)
Howover your games seen run great now, those binany you sent to me on mac. They did not run insane fast and such thing. Its did fell correct.


The games worked fine with FLIP before I updated to 1.41, but something changed and it doesn't anymore (on mac only).
The binaries I sent you works correctly fine because I downgraded BM again.