Ticket #4261: update_dsstore.applescript

File update_dsstore.applescript, 4.8 KB (added by ioerror, 9 years ago)

chrome apple script

Line 
1-- Copyright (c) 2011 The Chromium Authors. All rights reserved.
2-- Use of this source code is governed by a BSD-style license that can be
3-- found in the LICENSE file.
4
5-- Helpers
6on CloseFinderWindowsForPath(prefix)
7        tell application "Finder"
8                set windowList to Finder windows
9                repeat with aWindow in windowList
10                        if (target of aWindow as string) starts with prefix then
11                                close aWindow
12                        end if
13                end repeat
14        end tell
15end CloseFinderWindowsForPath
16
17on EjectDMG(productName)
18        tell application "Finder" to eject alias productName
19end EjectDMG
20
21-- Driver
22on run
23
24        -- Some vars
25        set tempDir to (path to "temp" from user domain as text) & "DS_STORE_WORK:"
26        set quotedTempDir to quoted form of POSIX path of tempDir
27        set rwDMG to tempDir & "RW.sparseimage"
28        set quotedRWDMG to quoted form of POSIX path of rwDMG
29        set productName to text returned of (display dialog "Enter the product name" default answer "Google Chrome")
30        set quoteTgtBkgImageDir to quoted form of ("/Volumes/" & productName & "/.background")
31        set quoteTgtBkgImagePath to quoted form of ("/Volumes/" & productName & "/.background/background.png")
32        set quoteDSStorePath to quoted form of ("/Volumes/" & productName & "/.DS_Store")
33
34        -- Pick the dmg to start with
35        set srcDMG to choose file with prompt "Pick the reference DMG"
36        set quotedSrcDMG to quoted form of POSIX path of srcDMG
37
38        -- Collect the background image
39        set changeImagePrompt to display dialog "Change the background image?" buttons {"Yes", "No"}
40        if button returned of changeImagePrompt is "Yes" then
41                set doBkgImg to 1
42                set bkgImage to choose file with prompt "Pick the background png"
43                set quotedBkgImage to quoted form of POSIX path of bkgImage
44        else
45                set doBkgImg to 0
46        end if
47
48        -- Nuke and then make the temp dir so it starts empty
49        set cleanupTempDir to "rm -rf " & quotedTempDir
50        do shell script cleanupTempDir
51        do shell script "mkdir -p " & quotedTempDir
52
53        -- Convert to a RW DMG (use sparse bundle so it can grow with the update background, etc.)
54        set convertScript to "hdiutil convert " & quotedSrcDMG & " -format UDSP -o " & quotedRWDMG
55        do shell script convertScript
56
57        -- Mount the RW image
58        set attachScript to "hdiutil attach " & quotedRWDMG
59        do shell script attachScript
60        CloseFinderWindowsForPath(productName)
61
62        if doBkgImg is 1 then
63                -- Make sure the background dir exists
64                set makeBkdDirScript to "mkdir -p " & quoteTgtBkgImageDir
65                do shell script makeBkdDirScript
66
67                -- Copy the background into place
68                set copyBkgImgScript to "cp " & quotedBkgImage & " " & quoteTgtBkgImagePath
69                do shell script copyBkgImgScript
70        end if
71
72        tell application "Finder"
73                activate
74
75                -- Make a new window
76                set volumeName to productName & ":"
77                set myWin to make new Finder window to alias volumeName
78
79                -- Configure the window view options
80                set current view of myWin to icon view
81                set sidebar width of myWin to 0
82                set toolbar visible of myWin to false
83                set statusbar visible of myWin to false
84                set icon size of icon view options of myWin to 128
85                set arrangement of icon view options of myWin to not arranged
86                set shows item info of icon view options of myWin to false
87                set shows icon preview of icon view options of myWin to true
88                if doBkgImg is 1 then
89                        set bkgImagePath to volumeName & ".background:background.png"
90                        set bkgImage to alias bkgImagePath
91                        set background picture of icon view options of myWin to bkgImage
92                end if
93
94                -- Set the size/position
95                set bounds of myWin to {0, 0, 380, 540}
96                -- Assumed a 1440x900 screen, center the window vertically, and
97                -- set the left edge to half of the window's width.
98                set position of myWin to {190, 180}
99
100                -- Position the two icons
101                set theStuff to items of target of myWin
102                repeat with anItem in theStuff
103                        set appName to productName & ".app"
104                        if name of anItem is appName then
105                                set position of anItem to {190, 122}
106                        else if name of anItem is " " then
107                                set position of anItem to {190, 387}
108                        else
109                                activate
110                                display dialog "Something in the folder we don't know how to deal with!" buttons {"Doh!"}
111                                return 1
112                        end if
113                end repeat
114
115        end tell
116
117        -- Close the window to force the .DS_Store to get written
118        CloseFinderWindowsForPath(productName)
119
120        -- Unmount/Remount to make sure everything is flused to the .DS_Store
121        EjectDMG(productName)
122        do shell script attachScript
123
124        -- Copy the .DS_Store
125        set quotedSaveDSStoreTo to ""
126        try
127                activate
128                set saveDSStoreTo to choose file name with prompt "Save a copy of the .DS_Store as:"
129                set quotedSaveDSStoreTo to quoted form of POSIX path of saveDSStoreTo
130        on error
131                -- Eat the cancel so cleanup can happen
132                set quotedSaveDSStoreTo to ""
133        end try
134        if quotedSaveDSStoreTo is not "" then
135                set copyDSStoreScript to "cp " & quoteDSStorePath & " " & quotedSaveDSStoreTo
136                do shell script copyDSStoreScript
137        end if
138
139        -- Unmount
140        EjectDMG(productName)
141
142        -- Clean up the temp dir
143        do shell script cleanupTempDir
144
145        display dialog "All done!" buttons {"OK!"} default button "OK!"
146
147end run