Xojo Conferences
XDCMay2019MiamiUSA

Update MacOSLib AppleScript (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: shown event
Next thread: Re: TypeLibs and API Interfaces for Windows


TypeLibs and API Interfaces for Windows   -   Garth Hjelte
  Update MacOSLib AppleScript   -   Kem Tekinay
   Re: Update MacOSLib AppleScript   -   Arnaud Nicolet

Update MacOSLib AppleScript
Date: 02.08.11 00:31 (Mon, 1 Aug 2011 19:31:31 -0400)
From: Kem Tekinay
This is the latest revision of my AppleScript to update MacOSLib. It not only gets the files via SVN, it keeps a log and parses the version to let you know if there was actually an update. It also keeps the log trimmed to a set length.

This requires OS X 10.6 or better. Change the properties at the top of the script as required, then save as an Application Bundle.

I will not be supporting this so use at your own risk. If you would like the complied Application Bundle, e-mail me and I'll be happy to send it along.

<script>

property Max_Log_Length_In_KB : 1024
property Log_File_Name : "Update_Log.txt"
property Folder_Path_Within_Home : "Documents/RB Projects/Other Classes/MacOSLib/"
property SVN_Command : "svn checkout http://macoslib.googlecode.com/svn/trunk/"
property Log_File_Separator : "----------------------------------------"

property My_Version : 2.0
(* Revision History
1.0 First version.
2.0 Added log parsing and trimming. Moved properties to the top.
*)

on run

set destPath to (POSIX path of (path to home folder as string) & Folder_Path_Within_Home)
if last character of destPath is not "/" then set destPath to destPath & "/"
set logFileName to Log_File_Name

set logFilePath to destPath & logFileName

set sep to Log_File_Separator

-- Read the existing update log
try
set f to open for access logFilePath
on error
set f to false
end try

if f is not false then
set logLen to get eof f
if logLen > 0 then
set currentLog to read f
else
set currentLog to ""
end if
close access f
else -- No existing log
set logLen to 0
set currentLog to ""
end if

-- Get the previous revision
set previousRevision to ""
if currentLog is not "" then set previousRevision to Get_Last_Revision(currentLog)

log "Previous Revision: " & (previousRevision as string)

set cmd to SVN_Command & space & quoted form of destPath
try
set t to do shell script cmd
set noError to true
on error err
set noError to false
set t to err
end try

log t

set currentRevision to Get_Last_Revision(t)

set now to current date
set now to now as string

if currentLog is "" then
set logList to {}
else
set logList to {currentLog}
end if

set end of logList to now
set end of logList to t
set end of logList to sep

set AppleScript's text item delimiters to return
set newLog to logList as string
set AppleScript's text item delimiters to ""

set logLen to length of newLog
set maxLen to Max_Log_Length_In_KB * 1024
if logLen > maxLen then
-- Trim the log, but start at the first complete line
set newLog to text (logLen - maxLen) thru -1 of newLog
set AppleScript's text item delimiters to return
set logList to every text item of newLog
set logList to items 2 thru -1 of logList
set newLog to logList as string
set AppleScript's text item delimiters to ""
end if

-- Write out the complete log
set f to open for access logFilePath with write permission
set eof f to 0
write newLog to f
close access f

if noError then
set t to last paragraph of t
if previousRevision is not "" then
if previousRevision < currentRevision then
set t to t & (" (Previous revision was " & previousRevision & ".)") as string
else
set t to (t & " (Again.)") as string
end if
end if
set btns to {"Open Log", "OK"}
else -- There was an error
set btns to {"OK"}
end if

try
set r to display alert t buttons btns default button (count btns)
on error
set r to false
end try

set logAlias to POSIX file logFilePath as alias
if r is not false and button returned of r is "Open Log" then tell application "Finder" to open logAlias
end run

on Get_Last_Revision(str)
local lineList, aLine, r

set r to ""
if str is not "" then
set AppleScript's text item delimiters to return
set lineList to every text item of str
set AppleScript's text item delimiters to ""

repeat with aLine in lineList
if aLine starts with "Checked out revision " then
set r to (last word of aLine) as number
end if
end repeat
end if

return r
end Get_Last_Revision

</script>

Re: Update MacOSLib AppleScript
Date: 03.08.11 15:35 (Wed, 03 Aug 2011 16:35:15 +0200)
From: Arnaud Nicolet
Le 2 août 11 à 1:31, Kem Tekinay a écrit:

> This requires OS X 10.6 or better.

I guess it should read "OS X 10.6 or later". Not the same.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>