Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

script to install/update files

i am using package maker to install templates into iweb. i have managed to set the installer up to install the files into the correct locations - but i still need to be able to do one thing.

in order for the templates to work they need to update a templates.plist file. the only way i can see package maker to do is this by giving it a script.

how can i create a script that will update the file by adding certain plist lines into alphabetical orderded lists (in the plist file)?

i cannot replace the existing file because they might all have different templates installed! it sort of needs to merge the files as in file-merger!

another sidenote - i basically have no knowledge of applescript, so dont be to hard on me 😉

thanks,

max

iWeb Help & New Templates at my Site:, http://karreth.com/

Posted on Jun 1, 2007 4:10 AM

Reply
Question marked as Best reply

Posted on Jun 1, 2007 7:46 AM

Typically I would say using the shell command defaults is the way to go, but after looking at the file I don't think that will work. I don't have any templates to test this with, but this should work. It does make up a back up of your templates file to the desktop though just in case.

Currently it only works with one template, but by making the theme name variable a list and throwing the main logic block in a repeat through that list it would be easy to accomodate multiple files.

-- This works for a single file. Assuming though Multple files
-- it wouldn't be hard to make a list

(* ======== Change These For Your Theme ======== *)
set _themeName to "TESTING" -- Your Templates Name
set _themeVersion to "1.1" -- Some sort of version or compatability indicator??


(* === Nothing here down should need to be changed === *)

set _keys to {"About Me", "Blog", "Movie", "Photos", "Podcast", "Blank", "Welcome"}

set _deskPath to path to desktop as Unicode text
set _backupFolder to "iWeb Backup"
set _backupPath to _deskPath & _backupFolder
set _appPath to path to application "iWeb" as Unicode text
set _plistPath to _appPath & "Contents:Resources:English.lproj:Templates:TemplatesInfo.plist"

tell application "Finder"
if not (exists folder _backupPath) then
make new folder at _deskPath with properties {name:_backupFolder}
end if
tell application "Finder" to duplicate _plistPath to _backupPath
end tell

set _data to (read file _plistPath)

(* ====================== MAIN LOGIC BLOCK ======================*)
repeat with _keyValue in _keys
set _osString to ¬
" <key>" & _keyValue & "</key>
<dict>
<key>BLCategory</key>
<string>" & _keyValue & "</string>
<key>BLEntries</key>
<dict>"
set _insertString to ¬
" <key>" & _themeName & "</key>
<dict>
<key>displayName</key>
<string>" & _keyValue & "</string>
<key>fileName</key>
<string>" & _themeName & space & _keyValue & ".webtemplate</string>
</dict>"
set _theOffset to offset of _osString in _data
set _top to text 1 through (_theOffset + (count _osString)) of _data
set _bottom to text (_theOffset + (count _osString) + 1) through -1 of _data
set _data to _top & _insertString & (ASCII character 10) & _bottom
end repeat

set _osString to ¬
" <key>sortedThemes</key>
<array>"
set _insertString to ¬
" <dict>
<key>displayName</key>
<string>" & _themeName & "</string>
<key>keyName</key>
<string>" & _themeName & "</string>
<key>version</key>
<string>" & _themeVersion & " Themes</string>
</dict>"
set _theOffset to offset of _osString in _data
set _top to text 1 through (_theOffset + (count _osString)) of _data
set _bottom to text (_theOffset + (count _osString) + 1) through -1 of _data
set _data to _top & _insertString & (ASCII character 10) & _bottom
(* ==================== CLOSE MAIN LOGIC BLOCK ====================*)

try
close access file _plistPath
end try

set _fileRef to open for access _plistPath with write permission
set eof _fileRef to 0
write _data to _fileRef
close access _fileRef
5 replies
Question marked as Best reply

Jun 1, 2007 7:46 AM in response to MacPro.ButNOWebPro

Typically I would say using the shell command defaults is the way to go, but after looking at the file I don't think that will work. I don't have any templates to test this with, but this should work. It does make up a back up of your templates file to the desktop though just in case.

Currently it only works with one template, but by making the theme name variable a list and throwing the main logic block in a repeat through that list it would be easy to accomodate multiple files.

-- This works for a single file. Assuming though Multple files
-- it wouldn't be hard to make a list

(* ======== Change These For Your Theme ======== *)
set _themeName to "TESTING" -- Your Templates Name
set _themeVersion to "1.1" -- Some sort of version or compatability indicator??


(* === Nothing here down should need to be changed === *)

set _keys to {"About Me", "Blog", "Movie", "Photos", "Podcast", "Blank", "Welcome"}

set _deskPath to path to desktop as Unicode text
set _backupFolder to "iWeb Backup"
set _backupPath to _deskPath & _backupFolder
set _appPath to path to application "iWeb" as Unicode text
set _plistPath to _appPath & "Contents:Resources:English.lproj:Templates:TemplatesInfo.plist"

tell application "Finder"
if not (exists folder _backupPath) then
make new folder at _deskPath with properties {name:_backupFolder}
end if
tell application "Finder" to duplicate _plistPath to _backupPath
end tell

set _data to (read file _plistPath)

(* ====================== MAIN LOGIC BLOCK ======================*)
repeat with _keyValue in _keys
set _osString to ¬
" <key>" & _keyValue & "</key>
<dict>
<key>BLCategory</key>
<string>" & _keyValue & "</string>
<key>BLEntries</key>
<dict>"
set _insertString to ¬
" <key>" & _themeName & "</key>
<dict>
<key>displayName</key>
<string>" & _keyValue & "</string>
<key>fileName</key>
<string>" & _themeName & space & _keyValue & ".webtemplate</string>
</dict>"
set _theOffset to offset of _osString in _data
set _top to text 1 through (_theOffset + (count _osString)) of _data
set _bottom to text (_theOffset + (count _osString) + 1) through -1 of _data
set _data to _top & _insertString & (ASCII character 10) & _bottom
end repeat

set _osString to ¬
" <key>sortedThemes</key>
<array>"
set _insertString to ¬
" <dict>
<key>displayName</key>
<string>" & _themeName & "</string>
<key>keyName</key>
<string>" & _themeName & "</string>
<key>version</key>
<string>" & _themeVersion & " Themes</string>
</dict>"
set _theOffset to offset of _osString in _data
set _top to text 1 through (_theOffset + (count _osString)) of _data
set _bottom to text (_theOffset + (count _osString) + 1) through -1 of _data
set _data to _top & _insertString & (ASCII character 10) & _bottom
(* ==================== CLOSE MAIN LOGIC BLOCK ====================*)

try
close access file _plistPath
end try

set _fileRef to open for access _plistPath with write permission
set eof _fileRef to 0
write _data to _fileRef
close access _fileRef

Jun 1, 2007 8:47 AM in response to MacPro.ButNOWebPro

it runs it in the templates.plist file - but not at the correct position!

did i have to change any of the key_values parts? i didnt modify anything there cause you said i shouldnt need to modify anything.

here is what it installs at the very top:

<?xml version="1.0" encoding="UT <dict>
<key>displayName</key>
<string>Leaves</string>
<key>keyName</key>
<string>Leaves</string>
<key>version</key>
<string>1.0 Themes</string>
</dict>
F-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0/ <k <key>Leaves</key>
<dict>
<key>displayName</key>
<string>Welcome</string>
<key>fileName</key>
<string>Leaves Welcome.webtemplate</string>
</dict>
ey>Leaves</key>
<dict>
<key>displayName</key>
<string>Blank</string>
<key>fileName</key>
<string>Leaves Blank.webtemplate</string>
</dict>
<key>Leaves</key>
<dict>
<key>displayName</key>
<string>Podcast</string>
<key>fileName</key>
<string>Leaves Podcast.webtemplate</string>
</dict>
<key>Leaves</key>
<dict>
<key>displayName</key>
<string>Photos</string>
<key>fileName</key>
<string>Leaves Photos.webtemplate</string>
</dict>
<key>Leaves</key>
<dict>
<key>displayName</key>
<string>Movie</string>
<key>fileName</key>
<string>Leaves Movie.webtemplate</string>
</dict>
<key>Leaves</key>
<dict>
<key>displayName</key>
<string>Blog</string>
<key>fileName</key>
<string>Leaves Blog.webtemplate</string>
</dict>
/EN" "ht <key>Leaves</key>
<dict>
<key>displayName</key>
<string>About Me</string>
<key>fileName</key>
<string>Leaves About Me.webtemplate</string>
</dict>


whats wrong? my template is called Leaves.

script to install/update files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.