Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Goftrey

macrumors 68000
Original poster
May 20, 2011
1,853
75
Wales, UK
Hey guys, I've always been one to tinker around in Photoshop, creating icons/themes etc. for personal use. And it occurred to me that maybe some other people may enjoy them too - so I decided to put together an installer.

PackageMaker makes putting a .mpkg together incredibly simple. It's pretty much a drag & drop process all the way.

However - I've hit a little issue. I've made the installer require a restart (instead of making the user jump in to terminal & 'killall' everything manually), but for whatever reason this doesn't refresh the icons in the dock. The remain in the same state as they were in prior to the install. You can get around this by simply dragging the app out of the dock & re-adding it again. But that defeats the whole point of the 'automated' installer. I figured out this happens because the icon cache isn't updated.

After installing the theme, typing these commands 'refreshes' the dock & changes the icons, eliminating the need to drag the icons out of the dock & re-add them;

Code:
sudo find /private/var/folders/ -name com.apple.dock.iconcache

*Enter admin password*

sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \; 2>/dev/null

killall Dock

My question is - how do I add this script into the installer itself?

Thanks.

PS. The same issue applies when uninstalling the theme & returning to the original OS X icons.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,424
A sea of green
Come on guys! 500 views & not one of you know?

Just so you know, not all "views" are humans. Some will be web-crawlers, such as for search engines.

And speaking of search engines, when I google the search terms packagemaker script I find a lot of articles that mention the different places where a script can be placed in an installer package. Which leads me to ask the question: What have you tried?

If you tried searching, what terms did you search for (post actual search terms)? What did you find (post typical URLs)? Why was what you found unable to answer your question?

Did you consider asking your question in a forum where more PackageMaker expertise might be available, such as one of Apple's discussions?


I should also point out that there's no chance that the 'sudo' command in an installer script will be able to prompt for an admin password. The install needs to run in its entirety with elevated privileges (i.e. as root). The installer will then have the responsibility to prompt for the admin password, and the installation will then run as root. If you don't know how to do that in PackageMaker, try googling packagemaker admin authorization.

Also, there's no need to use this in 'find':
Code:
-exec rm {} \;
when there's this:
Code:
-delete
unless you're using a really old version of 'find', which makes me wonder what OS version you're targeting.
 

Goftrey

macrumors 68000
Original poster
May 20, 2011
1,853
75
Wales, UK
Just so you know, not all "views" are humans. Some will be web-crawlers, such as for search engines.

And speaking of search engines, when I google the search terms packagemaker script I find a lot of articles that mention the different places where a script can be placed in an installer package. Which leads me to ask the question: What have you tried?

If you tried searching, what terms did you search for (post actual search terms)? What did you find (post typical URLs)? Why was what you found unable to answer your question?

Did you consider asking your question in a forum where more PackageMaker expertise might be available, such as one of Apple's discussions?

If you want search terms, then here's just a few;
PackageMaker AppleScript
Add Terminal Command PackageMaker
Post Install Script PackageMaker

There's about 2 dozen of those types of searches with the words played around with, amounting to the same results. I've looked in the Apple Support forums, and decided to post here before going there. As the experiences I've found on that site have are, well - not helpful to say the least.

I should also point out that there's no chance that the 'sudo' command in an installer script will be able to prompt for an admin password. The install needs to run in its entirety with elevated privileges (i.e. as root). The installer will then have the responsibility to prompt for the admin password, and the installation will then run as root. If you don't know how to do that in PackageMaker, try googling packagemaker admin authorization.

Also, there's no need to use this in 'find':
Code:
-exec rm {} \;
when there's this:
Code:
-delete
unless you're using a really old version of 'find', which makes me wonder what OS version you're targeting.

I'm pretty new to pretty anything terminal based so go easy on me! :p

I'm creating the installer individually for each version of OS X (as they use different icons in different places & use different formats in some cases). I'm supporting OS X 10.4 Tiger through OS X 10.9 Mavericks (when's it let loose).

So onto the admin quote - you're saying that as long as admin auth. is ticked (as it already is) the commands will execute straight off the bat?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,424
A sea of green
If you want search terms, then here's just a few;
PackageMaker AppleScript
Add Terminal Command PackageMaker
Post Install Script PackageMaker

There's about 2 dozen of those types of searches with the words played around with, amounting to the same results. I've looked in the Apple Support forums, and decided to post here before going there. As the experiences I've found on that site have are, well - not helpful to say the least.

What were these "same results"? Why were they unsatisfactory? Here's an example of what I'm looking for in your answer.

I googled packagemaker script. The top result was this article on Stack Overflow:
http://stackoverflow.com/questions/640701/using-packagemaker-to-run-a-script-on-install

In that article, it says this (among other answers):
postinstall / postupgrade: This script is launched after the files in the package have been installed. See (preinstall / preupgrade) to see which one is launched.

postflight: This script is launched after the postinstall / postupgrade script or when the package has been installed.
To me, this seems to clearly identify three possible scripts that could be used to run a post-install, a post-upgrade, or a post-flight series of scripted actions. There are also links to other articles that explain exactly which of these scripts is run in which circumstances. The google results also have other articles, some on Stack Overflow and some on other sites.

To me, those three possible scripts cover exactly what you want to do: perform some actions after the main install has completed. So my question at this point is this: Why are those three possible scripted actions unsatisfactory?

Is it because you don't know which script is run when? The links to articles explaining packagemaker scripts would likely explain that.

Is it because you can't figure out how to tell packagemaker to use your script as the postflight script (or whatever position you choose to run your script in)?

Did you try any experiments? E.g. making a simple script, adding it to the package being built, and then test it simply to see what happens? For example, a script that uses the 'say' command to speak a distinct word, such as 'say post flight' in the postflight script?

In other words, I can't figure out exactly where the problem is. Are you stuck because you don't understand packagemaker scripts? Are you stuck because you don't know how to tell packagemaker to add a script?

Exactly what is unsatisfactory?


I'm pretty new to pretty anything terminal based so go easy on me! :p
And you're learning these commands using what resource? A book? A tutorial? Random searches?


I'm creating the installer individually for each version of OS X (as they use different icons in different places & use different formats in some cases). I'm supporting OS X 10.4 Tiger through OS X 10.9 Mavericks (when's it let loose).
Using the same version of packagemaker? Which would be what?

If it seems like I'm asking a lot of questions, it's because details can be important.
http://www.mikeash.com/getting_answers.html


So onto the admin quote - you're saying that as long as admin auth. is ticked (as it already is) the commands will execute straight off the bat?
Have you tried something to see what happens? If not, do so, take careful notes, and post the results. If you're leery of damaging something, then use placeholder actions like 'say some text' to speak things, and see what it says.

I'll also suggest the 'id' command, which will output the current user id. I assume you already know how to read its man page (and what a man page is).

Some things are best learned by discovery, not least because you'll remember them better if you plot your own course and actually find out what works and what doesn't. You'll also probably learn more about what's really happening, rather than going by rote.

I find that the process of mapping out a systematic approach not only gives me a better idea of what to do and what to expect, it also gives me ideas of how to avoid making foolish mistakes, such as by using placeholders instead of actual 'rm' commands (or in addition to them).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.