Wednesday 12 March 2014

Apple: Get Values from PLIST File, Save The Values In A Text File and Restart Caching Service of Mac OS X Server with AppleScript

The AppleScript below allows you to:
1.  Get the values of properties from a PLIST file.
2.  Save the values of properties in a text file.
3.  Restart the caching service of Mac OS X Server
set the plistfile_path to "/Library/Server/Caching/Logs/LastState.plist"
tell application "System Events"
    set p_list to property list file (plistfile_path)
    set byte to text of property list item "TotalBytesReturned" of p_list
    set request to text of property list item "TotalBytesRequested" of p_list
    set peer to text of property list item "TotalBytesFromPeers" of p_list
    set origin to text of property list item "TotalBytesFromOrigin" of p_list
    set myDate to date string of (current date)
    set myTime to time string of (current date)
    set myDateTime to myTime & " " & myDate
end tell

try
    set theFile to (((path to desktop) as text) & "OUTPUT:" & "TotalBytes.txt") as alias
    set N to open for access theFile with write permission
    get eof N
    if result > 0 then
        set theText to read N
        set eof N to 0
        write myDateTime & return & return & "Total Bytes Returned" & return & byte & return & return & "Total Bytes Requested" & return & request & return & return & "Total Bytes From Peers" & return & peer & return & return & "Total Bytes From Origin" & return & origin & return & return & return & return & return & return & theText to N
    end if
    close access N
end try

do shell script "Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin stop caching" password "Weneed2prepare@2012" with administrator privileges
delay 60
do shell script "Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin start caching" password "Weneed2prepare@2012" with administrator privileges

No comments:

Post a Comment