use framework "Foundation"
use script "FileManagerLib" version "2.3.5"
use script "List" version "1.0"
use script "Myriad Tables Lib" version "1.0.12"
use script "PrefsStorageLib" version "1.1.0"
use scripting additions
property lastAppPosition : {30, 30, 600, 600}
property lastLibPosition : {30, 30, 600, 600}
property appsInfo : {}
property libsInfo : {}
property allLibs : true
property allApps : true
property selectedLibs : {}
property selectedApps : {}
property selectedAppRows : {}
property selectedLibRows : {}
PersistentVariables()
--StorePersistentValues()
--RetreiveStoredValues()
set AppleScript's text item delimiters to {" ", ")"}
set sysVer to (current application's NSProcessInfo's processInfo()'s operatingSystemVersionString()) as text
set sysVer to text items of (sysVer as text)
set {sysVer, buildNum} to ({item 2 of sysVer, item 4 of sysVer})
set sysVer to {"--> Mac OS Version " & sysVer & " (" & buildNum & ")" as text}
set AppleScript's text item delimiters to {""}
repeat with x from 1 to count of appsInfo
set {appName, appVersion, appBuild, appBundleID, appScriptable} to item x of appsInfo
set {appName, appVersion, appBuild} to GetappsInfo(appBundleID)
set item x of appsInfo to {appName, appVersion, appBuild, appBundleID, appScriptable}
end repeat
set tableData to appsInfo
set tableTitle to "Application Info"
set addAppButton to "Add Applications"
set tablePrompt to "Select which apps to copy version build info"
set columnHeadings to {"Name", "Version", "Build", "Bundle ID", "Scriptable?"}
set selectedAppRows to GenerateSelectedRowNumbers(tableData, selectedApps)
set {lastAppPosition, selectedApps, selectedAppRows, appsInfo} to DisplayTable(tableData, tableTitle, tablePrompt, columnHeadings, lastAppPosition, selectedAppRows, addAppButton)
StorePersistentValues()
set versionExportText to {sysVer}
if selectedApps is not {} then
set the end of versionExportText to {"", "--Applications"}
repeat with thisApp in selectedApps
set {appName, appVersion, appBuild} to thisApp
set appString to " --> " & appName & " " & appVersion & " (" & appBuild & ")"
set the end of versionExportText to appString
end repeat
end if
set libsInfo to AllLibVersions()
set tableData to libsInfo
set addLibButton to "Add Script Libararies"
set tableTitle to "Script Library Versions"
set tablePrompt to "Select which libraries to copy version info"
set columnHeadings to {"Script Library Folder", "Name", "Version"}
set selectedLibRows to GenerateSelectedRowNumbers(tableData, selectedLibs)
set {lastLibPosition, selectedLibs, selectedLibRows, libsInfo} to DisplayTable(tableData, tableTitle, tablePrompt, columnHeadings, lastLibPosition, selectedLibRows, addLibButton)
StorePersistentValues()
if selectedLibs is not {} then
set the end of versionExportText to return & "--Script Libraries"
repeat with thisLib in selectedLibs
set {libFolder, libName, libVersion} to thisLib
set libString to " --> " & libName & " " & libVersion
set the end of versionExportText to libString
end repeat
end if
set AppleScript's text item delimiters to {return}
set versionExportText to versionExportText as text
--display dialog
set buttonList to {¬
("Done"), ¬
("Change"), ¬
("Copy") ¬
}
set DialogReply to display dialog ("Select Copy to send versions to the clipboard" & return & return & versionExportText) ¬
with title ("App and Script Library versions") ¬
buttons buttonList ¬
default button 3 ¬
cancel button 1 ¬
giving up after 60 ¬
with icon note
if button returned of DialogReply is "Copy" then set the clipboard to versionExportText
on AllLibVersions()
set saveTID to AppleScript's text item delimiters
set userDLibraryFolder to path to library folder ¬
from user domain ¬
as text
set systemDLibraryFolder to path to library folder ¬
from system domain ¬
as text
--tell application "Finder" to open item systemDLibraryFolder
set libVersions to LibFolderVersions(userDLibraryFolder, "Scripts Library - User")
set libVersions to libVersions & LibFolderVersions(systemDLibraryFolder, "Scripts Library - System")
--set libVersions to my SortLibVersions(libVersions)
return libVersions
end AllLibVersions
on DisplayTable(tableData, tableTitle, tablePrompt, columnHeadings, lastTablePosition, selectedRows, extraButtonName)
set multipleSelectionsAllowed to true
set canAddAndDelete to false
set editableColumns to missing value -- Number List
set rowNumbering to true
set emptySelectionAllowed to true
set rowTemplate to {item 1 of appsInfo}
set multipleLinesAllowed to true
set doubleclickMeansOK to true
set newTable to make new table with data tableData ¬
with title tableTitle ¬
with prompt tablePrompt ¬
multiple selections allowed multipleSelectionsAllowed ¬
can add and delete canAddAndDelete ¬
editable columns editableColumns ¬
column headings columnHeadings ¬
row numbering rowNumbering ¬
initially selected rows selectedRows ¬
empty selection allowed emptySelectionAllowed ¬
multiple lines allowed multipleLinesAllowed ¬
double click means OK doubleclickMeansOK
set OKButtonName to "OKAY"
set OKButtonIsDefault to true
set cancelButtonName to "Cancel"
set gridStyle to grid both --grid between columns -- grid between rows; grid between rows dashed;; grid both dashed between rows; between rows and columns grid none
set highlightedRows to {}
set alternateBackgrounds to true
set rowDragging to false
set columnReordering to false
set hiddenCancelButton to false
--modify columns in table newTable ¬
-- sort method sort none ¬
modify table newTable ¬
OK button name OKButtonName ¬
OK button is default OKButtonIsDefault ¬
cancel button name cancelButtonName ¬
extra button name extraButtonName ¬
grid style gridStyle ¬
highlighted rows highlightedRows ¬
alternate backgrounds alternateBackgrounds ¬
row dragging rowDragging ¬
column reordering columnReordering ¬
hidden cancel button hiddenCancelButton ¬
initial position lastTablePosition
set extendedResults to true
set tableResult to display table newTable ¬
extended results extendedResults
tell tableResult
set lastPosition to its final position
set valuesSelected to its values selected
set selectedRows to its rows selected
set valuesReturned to its values returned
end tell
return {lastPosition, valuesSelected, selectedRows, valuesReturned}
end DisplayTable
on GetApps(appNames)
set infoForApps to {}
tell application "System Events" to set allProcesses to processes whose background only is false
repeat with thisProcess in allProcesses
tell application "System Events"
tell thisProcess
properties
set appBundleID to bundle identifier
-- set appFile to path of application file
set appScriptable to has scripting terminology
end tell
end tell
set {fullAppName, appVer, appBundleVer} to GetappsInfo(appBundleID)
if fullAppName is in appNames then
set the end of infoForApps to {¬
fullAppName, ¬
appVer, ¬
appBundleVer, ¬
appBundleID, ¬
appScriptable ¬
}
end if
end repeat
return infoForApps
end GetApps
on GetappsInfo(appBundleID)
set appNSURL to current application's NSWorkspace's sharedWorkspace()'s URLForApplicationWithBundleIdentifier:appBundleID
set appBundle to current application's NSBundle's bundleWithURL:appNSURL
set fullAppName to (appBundle's infoDictionary()'s objectForKey:"CFBundleName") as text
set appVer to (appBundle's infoDictionary()'s objectForKey:"CFBundleShortVersionString") as text
set appBundleVer to (appBundle's infoDictionary()'s objectForKey:"CFBundleVersion") as text
return {fullAppName, appVer, appBundleVer}
end GetappsInfo
on getLibFilesFromFolder(aFolder, source)
--set LibApp to (aFolder as text) & "Shane's Script Library Pack.app:Contents:Library:Script Libraries:"
aFolder
try
set foundFiles to objects of aFolder as text ¬
searching subfolders false ¬
include invisible items false ¬
include folders false ¬
include files true ¬
result type files list
on error errText number errNum
set errorString to "Error Message: " & errText & return & return & "Error number: " & errNum as text
set buttonList to {¬
("Cancel"), ¬
("Okay") ¬
}
set errDialogReply to display dialog errorString ¬
with title ("Error: " & errNum) ¬
buttons buttonList ¬
default button 2 ¬
cancel button 1 ¬
giving up after 60 ¬
with icon note
if button returned of errDialogReply contains "Copy" then
set the clipboard to errorString
else if button returned of errDialogReply contains "Continue Error" then
error errText number errNum
end if
end try
set libFiles to {}
repeat with thisFile in foundFiles
set thisFile to thisFile as alias
--tell application "System Events" to set libVersion to version of thisLib
set fileInfo to (parse object thisFile)
set {fileName, fileExtension} to fileInfo's {name_stub, name_extension}
if fileName is not in libsInfo then set the end of libsInfo to fileName
if fileExtension is in {"scpt", "scptd"} then
set the end of libFiles to {source, fileName, thisFile}
else if fileExtension is "app" then
set appLibFolder to (thisFile as text) & "Contents:Library:Script Libraries:"
try
appLibFolder as alias
set appLibFiles to my getLibFilesFromFolder(appLibFolder, fileName)
set libFiles to libFiles & appLibFiles
end try
end if
end repeat
return libFiles
end getLibFilesFromFolder
on LibFolderVersions(libraryFolder, sourceDirectory)
try
set scriptLibraryFolder to libraryFolder & "Script Libraries" as alias
on error
return {}
end try
set libFiles to my getLibFilesFromFolder(scriptLibraryFolder, sourceDirectory)
--set the end of libFiles to "--> Script Libaries:"
set AppleScript's text item delimiters to {""}
set libVersions to {}
repeat with thisLibFile in libFiles
set thisLibFile to thisLibFile as item
if the class of thisLibFile is text then
set the end of libVersions to {libSource, thisLibFile, ""}
else
set {libSource, libName, libPath} to thisLibFile as list
tell application "System Events" to set libVersionNum to version of libPath
set the end of libVersions to {libSource, libName, libVersionNum}
end if
end repeat
return libVersions
end LibFolderVersions
on SortLibVersions(libVersions)
set libVersions to sort list libVersions
set sortedList to {}
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
repeat with thisItem in libVersions
set AppleScript's text item delimiters to {"-->"}
set {libLocation, libInfo} to text items of thisItem
if libLocation is not in sortedList then
set the end of sortedList to libLocation
end if
set the end of sortedList to {"", libInfo} as text
sortedList
end repeat
set AppleScript's text item delimiters to saveTID
return sortedList
end SortLibVersions
on PersistentVariables()
--set myPath to path to me
--prepare storage for (myPath)
prepare storage for domain "com.edstockly.AppLibVersionApp"
--default values {appsInfo:{}, libsInfo:{}, selectedLibs:{}, selectedApps:{}, lastPosition:{}}
my RetreiveStoredValues()
end PersistentVariables
on StorePersistentValues()
assign value appsInfo to key "appsInfo"
assign value libsInfo to key "libsInfo"
assign value selectedLibs to key "selectedLibs"
assign value selectedApps to key "selectedApps"
assign value lastAppPosition to key "lastAppPosition"
assign value selectedAppRows to key "selectedAppRows"
assign value selectedLibRows to key "selectedLibRows"
assign value lastLibPosition to key "lastLibPosition"
end StorePersistentValues
on RetreiveStoredValues()
set my appsInfo to value for key "appsInfo"
set my libsInfo to value for key "libsInfo"
set my selectedLibs to value for key "selectedLibs"
set my selectedApps to value for key "selectedApps"
set my selectedLibRows to value for key "selectedLibRows"
set my selectedAppRows to value for key "selectedAppRows"
set my lastAppPosition to value for key "lastAppPosition"
set my lastLibPosition to value for key "lastLibPosition"
end RetreiveStoredValues
on GenerateSelectedRowNumbers(tableList, selectedValues)
set selectedRowNumbers to {}
repeat with x from 1 to count of tableList
if item x of tableList is in selectedValues then set the end of selectedRowNumbers to x
end repeat
return selectedRowNumbers
end GenerateSelectedRowNumbers