One of the newer features that we have added to CMake is the ability to generate visually appealing DragNDrop packages for Mac OS X. In doing so, we have refined our layout script and now wish to share our work so that other projects can easily generate DragNDrop packages.
Generating these packages entails specifying a custom background image and AppleScript to CPack. While the new ability allows each project to have nearly full control over the process and the layout of a package, it does require knowledge of AppleScript and the techniques used to create a package.
Below, you can find the AppleScript that CMake uses to package itself. This AppleScript is also available on GitLab, as is the background image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<span style="font-family: terminal, monaco, monospace; font-size: 8pt; line-height: 1em;"> <span style="color: #0000ff;">on run argv set image_name</span> <span style="color: #800080;">to</span> item <span style="color: #ff0000;">1</span> <span style="color: #0000ff;">of argv tell</span> application <span style="color: #008000;">"Finder"</span> <span style="color: #0000ff;">tell disk</span> <span style="color: #000080;">image_name</span> <span style="color: #0000ff;"> -- wait</span> <span style="color: #800080;">for</span> <span style="color: #0000ff;">the image</span> <span style="color: #800080;">to</span> <span style="color: #0000ff;">finish mounting</span> <span style="color: #0000ff;">set open_attempts</span><span style="color: #800080;"> to</span> <span style="color: #ff0000;">0</span> <span style="color: #0000ff;">repeat</span> <span style="color: #800080;">while</span> <span style="color: #000080;">open_attempts</span> <span style="color: #0000ff;"><</span> <span style="color: #ff0000;">4</span> <span style="color: #800080;">try</span> <span style="color: #0000ff;">open</span> delay <span style="color: #ff0000;">1</span> <span style="color: #0000ff;">set open_attempts</span> <span style="color: #800080;">to</span> <span style="color: #ff0000;">5</span> <span style="color: #0000ff;">close on error errStr number errorNumber set open_attempts</span> <span style="color: #800080;">to</span> <span style="color: #000080;">open_attempts</span> <span style="color: #0000ff;">+</span> <span style="color: #ff0000;">1</span> delay <span style="color: #ff0000;">10</span> <span style="color: #800080;">end try end</span> <span style="color: #0000ff;">repeat</span> delay <span style="color: #ff0000;">5</span> <span style="color: #0000ff;"> -- open the image the first time</span> <span style="color: #800080;">and</span> save a <span style="color: #0000ff;">DS_Store with</span> <span style="color: #000080;">just</span> <span style="color: #0000ff;">-- background <span style="color: #800080;">and</span> icon setup open set current view of container window <span style="color: #800080;">to</span> icon view set theViewOptions <span style="color: #800080;">to</span> the icon view options of container window set background picture of theViewOptions <span style="color: #800080;">to </span><span style="color: #000000;">file</span> <span style="color: #008000;">".background:background.tif"</span> set arrangement of theViewOptions <span style="color: #800080;">to not</span> arranged set icon size of theViewOptions <span style="color: #800080;">to</span> <span style="color: #ff0000;">128</span> delay <span style="color: #ff0000;">5</span> close -- next setup the position of the app and Applications symlink -- plus hide all the window decoration open update without registering applications tell container window set sidebar width <span style="color: #800080;">to</span> <span style="color: #ff0000;">0</span> set statusbar visible <span style="color: #800080;">to false</span> set toolbar visible <span style="color: #800080;">to false</span> set the bounds <span style="color: #800080;">to</span> { <span style="color: #ff0000;">400</span>, <span style="color: #ff0000;">100</span>, <span style="color: #ff0000;">900</span>, <span style="color: #ff0000;">465</span> } set position of <span style="color: #000000;">item</span> <span style="color: #008000;">"CMake.app"</span> <span style="color: #800080;">to</span> { <span style="color: #ff0000;">133</span>, <span style="color: #ff0000;">200</span> } set position of <span style="color: #000000;">item</span> <span style="color: #008000;">"Applications"</span> <span style="color: #800080;">to</span> { <span style="color: #ff0000;">378</span>, <span style="color: #ff0000;">200</span> } <span style="color: #800080;">end</span> tell update without registering applications <span style="color: #000000;">delay</span> <span style="color: #ff0000;">5</span> close -- one last open <span style="color: #800080;">and</span> close so you can see everything looks correct open <span style="color: #000000;">delay</span> <span style="color: #ff0000;">5</span> close</span> <span style="color: #0000ff;"><span style="color: #800080;">end</span> tell <span style="color: #000000;">delay</span> <span style="color: #ff0000;">1</span> <span style="color: #800080;">end</span> tell <span style="color: #800080;">end</span> <span style="color: #000080;">run</span></span></span> |
The AppleScript can easily be modified and integrated by other projects. The only major change required is to edit line 42, which explicitly specifies the name of the package.
In preparation for the 5.2 release, the ParaView team integrated the above background image and AppleScript into the ParaView Superbuild to automatically create more visually appealing Mac packages. Special thanks goes to Sandia National Laboratories, which funded this effort.
We would also like to acknowledge Adam Strzelecki, who made the addition of the ability to CMake possible, as he designed the background image and the initial implementation.
CMake at SC16
In November, I will attend The International Conference for High Performance Computing, Networking, Storage and Analysis (SC16) along with other members of the CMake development team. I hope you will stop by the Kitware booth (#3437) to learn more about creating Mac OS X packages with CMake. Be sure to also ask us about the many open-source solutions we offer that leverage CMake, such as ParaView Catalyst, which ran on over one million cores earlier this year. We have posted our conference activities on our event listing, so take advantage of the opportunity to talk to us!
Pingback: Marcus D. Hanwell