Permalink
Browse files

Auto-assign app icon when building the installer

  • Loading branch information...
1 parent ddb4601 commit b278e5e2d01d68a7f0aeda7e9f8dc3997c1099e5 @deadprogram deadprogram committed Sep 9, 2011
Showing with 149 additions and 0 deletions.
  1. +148 −0 assignIcon.py
  2. +1 −0 build_installer.sh
  3. BIN kidsrubylogo.png
View
@@ -0,0 +1,148 @@
+#!/usr/bin/python
+#
+# ----------------------------------------------------------------
+#
+# DESCRIPTION:
+#
+# A Script that assigns an icon to a file or a folder
+#
+# (c) Ali Rantakari, 2007
+# http://hasseg.org
+# fromassigniconpythonscript.20.hasseg@spamgourmet.com
+#
+# ----------------------------------------------------------------
+#
+# REQUIRES:
+#
+# - OS X 10.4 (Tiger) or later
+# - Developer Tools installed (found on OS discs)
+#
+# ----------------------------------------------------------------
+#
+#
+
+import string, sys, os, shutil, tempfile
+
+
+
+
+
+# ----------------------------------------------------------------
+#
+# SETTINGS:
+#
+#
+
+
+# locations of CLI apps used
+#
+# system:
+#
+file = "/usr/bin/file"
+osascript = "/usr/bin/osascript"
+sips = "/usr/bin/sips"
+#
+# installed with developer tools:
+#
+setfile = "/Developer/Tools/SetFile"
+rez = "/Developer/Tools/Rez"
+derez = "/Developer/Tools/DeRez"
+#
+# all of the above in a list
+#
+usedcliapps = [file, osascript, sips, setfile, rez, derez]
+
+
+
+
+# - - - - - - - - - - - - - - - - - - - - - -
+# settings end here.
+# ----------------------------------------------------------------
+#
+
+
+
+
+
+
+# FUNCTIONS:
+
+def getMyBaseName():
+ return os.path.basename(sys.argv[0])
+
+def displayUsage():
+ print "Usage: "+getMyBaseName()+" [image] [target]"
+ print " "
+ print " [image] is the image file to be used as the icon"
+ print " [target] is the target file or folder to assign"
+ print " the icon to"
+ print " "
+
+def isImage(f):
+ o = os.popen(file+" -p \""+f+"\"", "r")
+ if (o.read().find("image") != -1):
+ return True
+ else:
+ return False
+
+def runInShell(cmd):
+ os.popen(cmd, 'r')
+
+
+
+
+
+
+
+# Script IMPLEMENTATION begins here ---------------------------
+# -------------------------------------------------------------
+#
+
+# make sure all of the used CLI apps exist in
+# their defined paths
+for i in usedcliapps:
+ if not os.path.exists(i):
+ print "Error! "+i+" does not exist!"
+ print " "
+ sys.exit(127)
+
+
+# make sure all required arguments are entered
+if len(sys.argv)<3:
+ displayUsage()
+ sys.exit(0)
+
+source = sys.argv[1]
+target = sys.argv[2]
+
+
+# validate argument types and paths
+if os.path.exists(source):
+ if os.path.exists(target):
+ if isImage(source):
+
+ # args ok -> assign icon
+ tempfile.gettempdir()
+ shutil.copyfile(source, tempfile.tempdir+"/temp-pic")
+ runInShell(sips+" -i \""+tempfile.tempdir+"/temp-pic\"")
+ runInShell(derez+" -only icns \""+tempfile.tempdir+"/temp-pic\" > \""+tempfile.tempdir+"/temprsrc.rsrc\"")
+ if os.path.isdir(target):
+ runInShell(rez+" -append \""+tempfile.tempdir+"/temprsrc.rsrc\" -o \"`printf \""+target+"/Icon\\r\"`\"")
+ else:
+ runInShell(rez+" -append \""+tempfile.tempdir+"/temprsrc.rsrc\" -o \""+target+"\"")
+ runInShell(setfile+" -a C \""+target+"\"")
+ os.remove(tempfile.tempdir+"/temp-pic")
+ os.remove(tempfile.tempdir+"/temprsrc.rsrc")
+
+ else:
+ print "Error! "+source+" is not an image file"
+ print " "
+ sys.exit(127)
+ else:
+ print "Error! "+target+" does not exist"
+ print " "
+ sys.exit(127)
+else:
+ print "Error! "+source+" does not exist"
+ print " "
+ sys.exit(127)
View
@@ -17,6 +17,7 @@ cleanup() {
build_launcher() {
cd build
../appify.sh ../kidsruby.sh "KidsRuby"
+ ../assignIcon.py ../kidsrubylogo.png KidsRuby.app
tar cvzf "KidsRuby.app.tar.gz" KidsRuby.app
cd ..
mv build/KidsRuby.app.tar.gz resources
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b278e5e

Please sign in to comment.