Hi,
I’m trying to write a script to change one or two values of two or three array items in “com.apple.finder.plist”. There is a menu for the options and that’s all done. This is just a test script to change one value of one array item. There may be easier ways of doing it but It does work well:
set plistFolder to path to preferences folder as Unicode text
-- make a plist test file by duplicating "com.apple.finder.plist"
tell application "Finder"
set plistFile to (duplicate (plistFolder & "com.apple.finder.plist")) as string
end tell
display dialog plistFile -- just for testing
tell application "System Events"
tell property list file plistFile
tell contents
set col_ExLVS_StVS to (property list item "columns" of property list item "ExtendedListViewSettings" of ¬
property list item "StandardViewSettings")
(*the property list item "columns" is an array of 10 items numbered from 0 to 9, where I need to change ¬
the value of the array item with the "identifier" = "label". By default this is the item numbered 5 ¬
but in fact being item 6 in the array. So I use (5 + 1) for clarity - at least for me*) ;)
set col_id to the value of property list item "identifier" of property list item (5 + 1) of col_ExLVS_StVS
set col_vis to the value of property list item "visible" of property list item (5 + 1) of col_ExLVS_StVS -- just for testing
set the value of property list item "visible" of property list item (5 + 1) of col_ExLVS_StVS to false
set col_vis_new to the value of property list item "visible" of property list item (5 + 1) of col_ExLVS_StVS -- just for testing
end tell
end tell
end tell
-- the following lines are just for testing
display dialog ((col_id as string) & ", " & col_vis as string) & ", " & col_vis_new as string
tell application "Finder" to open file plistFile -- open with the default app, in my case it is Xcode
However, I discovered that some :mad: users have changed the order of the array items, and thus hard coding the item number fails. What I need in this example is to cycle through the array items to find the item with the value of property list item “identifier” = “label”.
This is one of the many things I’ve tried and failed dismally and where I need your help disparately
set plistFolder to path to preferences folder as Unicode text
-- make a plist test file by duplicating "com.apple.finder.plist"
tell application "Finder"
set plistFile to (duplicate (plistFolder & "com.apple.finder.plist")) as string
end tell
display dialog plistFile -- just for testing
tell application "System Events"
tell property list file plistFile
tell contents
set col_ExLVS_StVS to (property list item "columns" of property list item "ExtendedListViewSettings" of property list item ¬
"StandardViewSettings")
repeat with i in col_ExLVS_StVS
-- This fails with "label" highlighted & the error message "can't make item 1 of . to integer"
if the value of property list item "identifier" of property list item i of col_ExLVS_StVS is "label" then
set col_id to the value of property list item "identifier" of property list item i of col_ExLVS_StVS
set col_vis to the value of property list item "visible" of property list item i of col_ExLVS_StVS -- just for testing
set the value of property list item "visible" of property list item i of col_ExLVS_StVS to true
set col_vis_new to the value of property list item "visible" of property list item i of col_ExLVS_StVS -- just for testing
end if
end repeat
end tell
end tell
end tell
-- the following lines are just for testing
display dialog ((col_id as string) & ", " & col_vis as string) & ", " & col_vis_new as string
tell application "Finder" to open file plistFile -- open with the default app, in my case it is Xcode
Please, can a charitable soul help me with this repeat coding. I’ll be forever grateful
Just in case you have no direct access to the xml form of the “com.apple.finder.plist”, I include here the relevant part of the xml file.
I know, I know that this all is exceedingly long but I’m disparate
set PLIST_File to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
...
<key>StandardViewSettings</key>
<dict>
<key>ExtendedListViewSettings</key>
<dict>
<key>calculateAllSizes</key>
<true/>
<key>columns</key>
<array>
<dict>
<key>ascending</key>
<true/>
<key>identifier</key>
<string>name</string>
<key>visible</key>
<true/>
<key>width</key>
<integer>300</integer>
</dict>
<dict>
<key>ascending</key>
<false/>
<key>identifier</key>
<string>dateModified</string>
<key>visible</key>
<true/>
<key>width</key>
<integer>130</integer>
</dict>
<dict>
<key>ascending</key>
<false/>
<key>identifier</key>
<string>dateCreated</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>130</integer>
</dict>
<dict>
<key>ascending</key>
<false/>
<key>identifier</key>
<string>size</string>
<key>visible</key>
<true/>
<key>width</key>
<integer>80</integer>
</dict>
<dict>
<key>ascending</key>
<true/>
<key>identifier</key>
<string>kind</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>150</integer>
</dict>
<dict>
<key>ascending</key>
<true/>
<key>identifier</key>
<string>label</string>
<key>visible</key>
<true/>
<key>width</key>
<integer>70</integer>
</dict>
<dict>
<key>ascending</key>
<true/>
<key>identifier</key>
<string>version</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>70</integer>
</dict>
<dict>
<key>ascending</key>
<true/>
<key>identifier</key>
<string>comments</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>100</integer>
</dict>
<dict>
<key>ascending</key>
<false/>
<key>identifier</key>
<string>dateLastOpened</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>130</integer>
</dict>
<dict>
<key>ascending</key>
<false/>
<key>identifier</key>
<string>dateAdded</string>
<key>visible</key>
<false/>
<key>width</key>
<integer>130</integer>
</dict>
</array>
<key>iconSize</key>
<real>16</real>
<key>scrollPositionX</key>
<real>0.0</real>
<key>scrollPositionY</key>
<real>0.0</real>
<key>showIconPreview</key>
<true/>
<key>sortColumn</key>
<string>name</string>
<key>textSize</key>
<real>10</real>
<key>useRelativeDates</key>
<true/>
<key>viewOptionsVersion</key>
<integer>0</integer>
</dict>
<key>IconViewSettings</key>
...
<key>ListViewSettings</key>
...
<key>SettingsType</key>
<string>StandardViewSettings</string>
</dict>
</plist>
"
Cheers,
Chris