07. Run various maintenance scripts
This document introduces some maintenance scripts for MacOSX. Those scripts are not related to Task3 directly but it will be useful to keep them as task and run them via menu bar.

Original Article(Japanese)

Please note that the author takes no responsibility for any damage caused by the use of those scripts.

(Reset QuickLook) - shell script
qlmanage -r

(Restart Dock) - shell script
killall Dock

(Restart Menu Bar) - shell script
killall SystemUIServer

(Restart Menu Bar) - shell script
killall SystemUIServer


(Restart Finder) - AppleScript
This script restarts Finder, reopen opening windows and reset file or folder selection.
property rt : return as text global check_finder_window_exists on run set check_finder_window_exists to false my main_routine() end run on main_routine() -- Save Finder's window information tell application "Finder" if Finder window 1 exists then set check_finder_window_exists to true set window_target to {} set window_toolbar to {} set window_statusbar to {} set window_sidebar to {} set window_bounds to {} set window_view to {} -- set window_view_options to {} set window_collapsed to {} set window_select_item_lists to {} set every_finder_window to every Finder window set window_count to count of every_finder_window repeat with each_window in every_finder_window tell each_window set beginning of window_collapsed to collapsed set beginning of window_target to target set beginning of window_toolbar to toolbar visible set beginning of window_statusbar to statusbar visible set beginning of window_sidebar to sidebar width set beginning of window_bounds to bounds set beginning of window_view to current view -- if current view is icon view then set beginning of window_view_options to icon view options -- if current view is list view then set beginning of window_view_options to list view options -- if current view is column view then set beginning of window_view_options to column view options -- if current view is flow view then set beginning of window_view_options to "" --set beginning of window_collapsed to collapsed end tell if collapsed of each_window is false then set index of each_window to 1 try -- Error handling for MacOSX10.4 set select_item to selection as alias list on error set select_item to {} end try else set select_item to {} end if set beginning of window_select_item_lists to select_item close each_window end repeat end if end tell my relaunch_finder() -- restart Finder -- Reopen Finder windows if check_finder_window_exists is true then tell application "Finder" close every Finder window delay 1 if Finder window 1 exists then close every Finder window delay 1 repeat with i from 1 to window_count make new Finder window to item i of window_target set toolbar visible of Finder window 1 to item i of window_toolbar set statusbar visible of Finder window 1 to item i of window_statusbar set sidebar width of Finder window 1 to item i of window_sidebar set bounds of Finder window 1 to item i of window_bounds set current view of Finder window 1 to item i of window_view -- if current view of Finder window 1 is icon view then set icon view options of Finder window 1 to item i of window_view_options -- if current view of Finder window 1 is list view then set list view options of Finder window 1 to item i of window_view_options -- if current view of Finder window 1 is column view then set column view options of Finder window 1 to item i of window_view_options delay 0.5 set selected_items to item i of window_select_item_lists try select selected_items end try --delay 0.5 set collapsed of Finder window 1 to item i of window_collapsed end repeat end tell end if --set check_finder_window_exists to false end main_routine -- Restart Finder -- -- Terminate on relaunch_finder() try tell application "Finder" to quit end try tell application "System Events" repeat 10 times if exists application process "Finder" then delay 1 try tell application "Finder" to quit end try else exit repeat end if end repeat end tell my activate_finder() end relaunch_finder -- launch Finder on activate_finder() try tell application "Finder" to activate on error delay 1 tell application "Finder" to activate end try tell application "System Events" repeat 10 times if exists application process "Finder" then exit repeat else delay 1 tell application "Finder" to activate end if end repeat end tell end activate_finder



(Rebuild Locate database) - AppleScript
set theMessage to "" set growlsticky to "no" try do shell script "/usr/libexec/locate.updatedb" on error errorMessage set theMessage to errorMessage set growlsticky to "yes" end try tell application "GrowlHelperApp" to notify with name "Task3MessageWorkNotification" title ("Rebuilding Locate database" as Unicode text) description (("has been done" & return & theMessage) as Unicode text) application name "task3runner" icon of application "task3runner" sticky growlsticky



(Repair disk permissions) - AppleScript
This script repairs disk permissions and notifies end of repair via Growl.
set theMessage to "" set growlsticky to "no" try set theMessage to do shell script "diskutil repairPermissions /" if theMessage is "" then set growlsticky to "yes" on error errorMessage set theMessage to theMessage & return & errorMessage set growlsticky to "yes" end try tell application "GrowlHelperApp" to notify with name "Task3MessageWorkNotification" title ("Repair disk permissions" as Unicode text) description (("has been done" & return & theMessage) as Unicode text) application name "task3runner" icon of application "task3runner" sticky growlsticky

 

To Top and Map