Change the icon in code on a Mac

BlitzMax Forums/BlitzMax Programming/Change the icon in code on a Mac

Grey Alien(Posted 2007) [#1]
Hi, I have some neat code to change the icon for my PC games, but has anyone managed to do this in code for the Mac? I've found this thread which tells you how to do it manually:

http://www.blitzbasic.com/Community/posts.php?topic=41986

and this one:

http://www.blitzbasic.com/Community/posts.php?topic=41222

But neither do it in code. Is that even possible?

Thanks in advance for any help you can offer.


jhans0n(Posted 2007) [#2]
Since the icon isn't actually part of the executable, but is part of the application package, it's probably a little more difficult than on Windows.

Maybe you could edit the info.plist file inside the package in code to point to a different icon name. I don't know if that would be picked up on the fly, though.


Grey Alien(Posted 2007) [#3]
Hmm, OK so when you compile an app on a Mac, it makes the package folder and gives it the BMax icon, but I was wanting to find some way to automatically make that icon a GAME icon. Perhaps it's an IDE issue? As if you could specify it in the IDE, it could make the package with the correct icon right?


jhans0n(Posted 2007) [#4]
Yes, I think it would have to be done from the IDE, or with a program that was executed after the package has been created.


Brucey(Posted 2007) [#5]
As jhanson says, the IDE would likely be a good place to have this functionality.

You kind of want a cross-platformable "Customize your project Icon" window - where you can specify a set of icons (different sizes) to be deployed with your application, included in the package on Mac, stored as application resources on Windows...

:o)


Grey Alien(Posted 2007) [#6]
sounds fantasic. Yes the IDE should have it built in...


nino(Posted 2007) [#7]
If we could add scripts to the build process this would be easy to do. I bash:

cp myGame.icns myGame.app/Contents/Resources/myGame.icns

after building but it would be nice if I could run that as part of the build


Grey Alien(Posted 2007) [#8]
Agreed. How do you turn that into a script or batch file equivalent on a Mac (I'm a Mac noob) as I'm still copying it in manually each time. Thanks.


degac(Posted 2007) [#9]
Can bash scripts be invoked via system_ command?

If yes, it should be easy changing the IDE to manage this script, modifing the BuildSource Method (standard IDE).


nino(Posted 2007) [#10]
yeah.. I have that in a file called blabla.bash

then in the console you'd do

bash blabla.bash


There's ways to use variables in a bash script so it would be something like

cp $var.icns $var.app/Contents/Resources/$var.icns

but I'm not exactly sure how you do it.


degac(Posted 2007) [#11]
I'm testing this piece of code
Local fileicon$=RequestFile("Icon name")
local fileapp$=RequestFile("Application name")
local newfileicon$="/"+StripDir(fileIcon)
local com$=chr(24)+"cp "+fileicon+" "+fileapp+"/Contents/Resources"+newfileicon+chr(34)
system_ com

print "ICON: "+fileicon
print "APP : "+fileapp
print "COM : "+com

but I have an error when running the 'com' instruction: No such file or directory
Any clue?
In any case I've tested via Terminal to change the icon like suggested, but I dont' understand if ICON_NAME and APP_NAME *must* be identical or not...

Tested on Mac OS X 10.3.9 - Bmax 1.26


Grey Alien(Posted 2007) [#12]
Have you put .app on the end of fileapp? You need it.


degac(Posted 2007) [#13]
I run the program and I choose this 2 files:

Font.icns
Font.app

In the output window of MaxIDE I can see the name of the choosen files (and they are correct).

The error raises in the call to the system_ command
sh: line 1: cp /Users/degac/Desktop/Font.icns /Users/degac/Desktop/Font.app/Contents/Resources/Font.icns: No such file or directory


For test I copied&pasted the cp... to the Terminal - no error


Brucey(Posted 2007) [#14]
The error message is telling you that there is no command called "cp /Users/degac/Desktop/Font.icns /Users/degac/Desktop/Font.app/Contents/Resources/Font.icns".
It appears that system_ is taking your string literally - which isn't what you want it to do.

You may find there's less hassle to use Stream Read/Write to do a "copy".


degac(Posted 2007) [#15]
Doh!
Thanks to clear out the problem.