Skip to content

Commit 160b50d

Browse files
Convert the OSX DMG prettifier script to text
Instead of a .scpt binary blob.
1 parent 8778584 commit 160b50d

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

tools/make-dmg-pretty.applescript

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
on run argv
2+
if the number of items of argv < 2 then
3+
display alert "Usage: make-dmg-pretty <volume name> <background image>"
4+
return "Error: invalid parameters"
5+
end if
6+
7+
set dmgIn to item 1 of argv
8+
set backgroundImage to POSIX file (item 2 of argv)
9+
tell application "Finder"
10+
11+
-- Delay to make sure the disk has had time to mount
12+
delay 10
13+
14+
tell disk dmgIn
15+
open
16+
17+
-- Path to this volume
18+
set diskPath to POSIX path of (it as alias)
19+
20+
-- Remove any existing preferences
21+
do shell script "rm -f " & quoted form of (diskPath & "/.DS_Store")
22+
23+
-- Remove any existing background folder
24+
do shell script "rm -rf " & quoted form of (diskPath & "/.background")
25+
26+
-- Remove any existing Applications alias
27+
if exists item "Applications" then
28+
delete item "Applications"
29+
end if
30+
31+
-- Create a new alias to the Applications folder
32+
make new alias at it to POSIX file "/Applications"
33+
34+
-- Create a hidden directory for the folder background
35+
make new folder at it with properties {name:".background"}
36+
37+
-- Copy the background image into place
38+
-- AppleScript seems to treat "." directories as neither files nor folders so the shell is needed here
39+
do shell script "cp " & quoted form of POSIX path of backgroundImage & " " & quoted form of (diskPath & "/.background/bg.tiff")
40+
41+
-- Set the position of the icons
42+
set fileList to every item of it
43+
repeat with i in fileList
44+
-- We're slightly fuzzy here as the app bundle name varies with edition and version
45+
if the name of i is "Applications" then
46+
set the position of i to {240, 393}
47+
else if the name of i ends with ".app" then
48+
set the position of i to {240, 120}
49+
end if
50+
end repeat
51+
52+
-- Close and re-open the window to force refresh
53+
close
54+
open
55+
56+
-- Configure the Finder window's appearance
57+
set the current view of container window to icon view
58+
set toolbar visible of container window to false
59+
set statusbar visible of container window to false
60+
set the bounds of container window to {100, 100, 580, 645}
61+
set viewOptions to the icon view options of container window
62+
set arrangement of viewOptions to not arranged
63+
set icon size of viewOptions to 128
64+
set text size of viewOptions to 16
65+
set background picture of viewOptions to file "bg.tiff" of item ".background"
66+
67+
-- According to http://joemaller.com/659/setting-icon-position-and-window-size-on-disk-images/, Finder sometimes does not save the size and position of a window until it detects user interaction on either the window's resizing handle or its zoom button. Simulate two clicks on the zoom button to trigger the save.
68+
--set theWindow to container window
69+
--tell application "System Events" to tell process "Finder" to click button 2 of theWindow
70+
--tell application "System Events" to tell process "Finder" to click button 2 of theWindow
71+
72+
-- Update everything after a delay to allow Finder to synchronise
73+
delay 10
74+
update without registering applications
75+
76+
-- Eject the disk image
77+
eject
78+
79+
-- Delay to allow unmounting
80+
delay 10
81+
end tell
82+
end tell
83+
end run

tools/make-dmg-pretty.scpt

-13.7 KB
Binary file not shown.

tools/make-dmg-pretty.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fi
77
volume="$1"
88
background=$(cd $(dirname "$2") && pwd)/$(basename "$2")
99

10-
script=$(dirname ${BASH_SOURCE[0]})/make-dmg-pretty.scpt
10+
script=$(dirname ${BASH_SOURCE[0]})/make-dmg-pretty.applescript
1111

1212
osascript "${script}" "${volume}" "${background}"

0 commit comments

Comments
 (0)