I would either add a button to the table, which when clicked, would bring up the additional info or setDoubleAction: and handle the event there. You can also use tableViewSelectionDidChange:, but this will execute every time a row selection is changed.
Unfortunately I’m somewhat new to Applescriptobjc, and don’t know what the following means (from the setDoubleAction page)…
For the method to have any effect, the receiver’s action and target must be set to the class in which the selector is declared. See Action Messages for additional information on action messages.
I’ve looked at Action Messages, and the info there is meaningless to me.
I’ve got the action doDoubleClick_(sender) working. Is that part of what I need to do?
Now, my problem iss that the information returned is displayed in Chinese charactersn and won’t copy to the clipboard.
Anyone know why?
Regards
Santa
on doDoubleClick_(sender)
if aTableView's selectedRow as integer is not equal to -1 then
my setDoubleClickedSelectedRow_(aTableView's selectedRow as integer)
set thisClient to theDataSource's objectAtIndex_(doubleClickedSelectedRow as integer)
display dialog thisClient as text
end if
end doDoubleClick_
I finally worked it out from the example (where ‘Client’ is the name of the column).
Thanks Craig.
on doDoubleClick_(sender)
if aTableView's selectedRow as integer is not equal to -1 then
my setDoubleClickedSelectedRow_(aTableView's selectedRow as integer)
set thisClient to theDataSource's objectAtIndex_(doubleClickedSelectedRow as integer)
set theClientname to (thisClient's valueForKey_("Client"))
display dialog theClientname as text
end if
end doDoubleClick_
I’m now having trouble inserting the data into the second table. I’ve tried pure guesswork to no avail, so am back for help. I simply can’t find any useful info on using multiple tables.
I’ll post all my code, and hope someone can set me straight.
Regards
Santa
--
-- Illustrator_Interface_Data_ReaderAppDelegate.applescript
-- Illustrator Interface Data Reader
--
-- Created by Brian Christmas on 8/01/10.
-- Copyright 2010 MeSelf. All rights reserved.
--
property NSMutableArray : class "NSMutableArray"
script Illustrator_Interface_Data_ReaderAppDelegate
property parent : class "NSObject"
property NSUserDefaults : class "NSUserDefaults" of current application
property doubleClickedSelectedRow : -1
property startingList : missing value
property YearList : missing value
property TextYear : missing value
property OperatorList : missing value
property TextOperator : missing value
property aTableView : missing value
property aTableView2 : missing value
property ClientColumn : missing value
property aWindow : missing value
property theDataSource : {}
property theDataSource2 : {}
property theClientFinalList : ""
property TheCountList : ""
property TheAverageList : ""
property TheMinList : ""
property TheMaxList : ""
property theVisibility : true
property windowMain : missing value
property information : missing value
global ptd
global MMFolder
global DataStart
global DataYear
global DataOperator
global SelectedClient
##################################################
# TableView
on applicationShouldHandleReopen_hasVisibleWindows_(sender)
windowMain's makeKeyAndOrderFront_(sender)
return true
end applicationShouldHandleReopen_hasVisibleWindows_
on tableView_objectValueForTableColumn_row_(aTableView, aColumn, aRow)
if theDataSource's |count|() is equal to 0 then return end
set ident to aColumn's identifier
set theRecord to theDataSource's objectAtIndex_(aRow)
set theValue to theRecord's objectForKey_(ident)
return theValue
end tableView_objectValueForTableColumn_row_
on numberOfRowsInTableView_(aTableView)
try
if theDataSource's |count|() is equal to null then
return 0
else
return theDataSource's |count|()
end if
on error
return 0
end try
end numberOfRowsInTableView_
on tableView_sortDescriptorsDidChange_(aTableView, oldDescriptors)
set sortDesc to aTableView's sortDescriptors()
theDataSource's sortUsingDescriptors_(sortDesc)
aTableView's reloadData()
end tableView_sortDescriptorsDidChange_
##################################################
# Application
on awakeFromNib()
set theDataSource to NSMutableArray's alloc()'s init()
set theDataSource2 to NSMutableArray's alloc()'s init()
end awakeFromNib
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
--set theDataSource to NSMutableArray's alloc()'s init()
--set theDataSource2 to NSMutableArray's alloc()'s init()
set thePListFolderPath to path to preferences folder from user domain as text
set theNewthePListFolderPath to thePListFolderPath & "Meself"
tell application "Finder"
if not (exists folder theNewthePListFolderPath) then make new folder at thePListFolderPath with properties {name:"MeSelf"}
end tell
set ptd to path to desktop as text
set MMFolder to "Mail Manager Folder"
set MMFolderFiller to {}
set end of MMFolderFiller to "Mail Manager Folder"
set end of MMFolderFiller to "Disk Jobs"
startingList's removeAllItems()
startingList's addItemsWithTitles_(MMFolderFiller)
YearList's removeAllItems()
OperatorList's removeAllItems()
YearList's setEnabled_(false)
TextYear's setHidden_(true)
OperatorList's setEnabled_(false)
TextOperator's setHidden_(true)
end applicationWillFinishLaunching_
on tableDoubleClicked()
say 3
if aTableView's selectedRow as integer is not equal to -1 then
my setDoubleClickedSelectedRow_(aTableView's selectedRow as integer)
set thisBook to theDataSource's objectAtIndex_(doubleClickedSelectedRow as integer)
my setTheStatus_(thisBook's valueForKey_("theStatus"))
my setBookTitle_(thisBook's valueForKey_("bookTitle"))
my setTheAuthor_(thisBook's valueForKey_("theAuthor"))
end if
end tableDoubleClicked
on doDoubleClick_(sender)
say 1
if aTableView's selectedRow as integer is not equal to -1 then
my setDoubleClickedSelectedRow_(aTableView's selectedRow as integer)
set thisClient to theDataSource's objectAtIndex_(doubleClickedSelectedRow as integer)
set SelectedClient to (thisClient's valueForKey_("Client")) as text
my fetchData()
end if
end doDoubleClick_
on chooseStart_(sender)
aTableView's reloadData()
set DataStart to startingList's titleOfSelectedItem() as text
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to name of every folder of folder (ptd & MMFolder) as list
set theList to {"Every Year"}
repeat with x in temp
if "Ill Interface Data" is in x then set end of theList to word 4 of x
end repeat
end tell
else
tell application "Finder"
set temp to name of every folder of disk "Jobs" as list
set theList to {"Every Year"}
repeat with x in temp
if "Ill Interface Data" is in x then set end of theList to word 4 of x
end repeat
end tell
end if
OperatorList's setEnabled_(false)
TextOperator's setHidden_(true)
OperatorList's removeAllItems()
YearList's removeAllItems()
YearList's addItemsWithTitles_(theList)
YearList's setEnabled_(true)
TextYear's setHidden_(false)
end chooseStart_
on chooseYear_(sender)
set theDataSource to NSMutableArray's alloc()'s init()
aTableView's reloadData()
set DataYear to YearList's titleOfSelectedItem() as text
if DataYear = "Every Year" then
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if item 1 of y is not in theOpList then set end of theOpList to item 1 of y
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if item 1 of y is not in theOpList then set end of theOpList to item 1 of y
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
end if
else
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if item 1 of y is not in theOpList then set end of theOpList to item 1 of y
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if item 1 of y is not in theOpList then set end of theOpList to item 1 of y
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
end if
end if
set theList to {"Every Operator"}
repeat with x in theOpList
set end of theList to x
end repeat
OperatorList's removeAllItems()
OperatorList's addItemsWithTitles_(theList)
OperatorList's setEnabled_(true)
TextOperator's setHidden_(false)
end chooseYear_
on chooseOperator_(sender)
set DataOperator to OperatorList's titleOfSelectedItem() as text
if DataYear = "Every Year" then
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to DataOperator
set theClientList to {}
set theTimeList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
set end of theClientList to item 2 of y
set end of theTimeList to item 4 of y
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to DataOperator
set theClientList to {}
set theTimeList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
set end of theClientList to item 2 of y
set end of theTimeList to item 4 of y
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
end if
else
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to DataOperator
set theClientList to {}
set theTimeList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
set end of theClientList to item 2 of y
set end of theTimeList to item 4 of y
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to DataOperator
set theClientList to {}
set theTimeList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
set end of theClientList to item 2 of y
set end of theTimeList to item 4 of y
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
end if
end if
set theClientFinalList to {}
set TheCountList to {}
set TheAverageList to {}
set TheMinList to {}
set TheMaxList to {}
set theMin to 0
set theMax to 0
set theAverage to 0
set theTotal to 0
set theCount to 0
try
repeat with x from 1 to count of theClientList
if theClientFinalList = {} then
set end of theClientFinalList to item x of theClientList
set end of TheCountList to 1
set theVariable to item x of theTimeList
set end of TheAverageList to theVariable
set end of TheMinList to theVariable
set end of TheMaxList to theVariable
set theMin to theVariable
set theMax to theVariable
set theTotal to theTotal + theVariable
set theCount to theCount + 1
else
set theFoundFlag to false
repeat with y from 1 to count of theClientFinalList
if item y of theClientFinalList = item x of theClientList then
set item y of TheCountList to (item y of the TheCountList) + 1
set item y of TheAverageList to (item y of TheAverageList) + (item x of theTimeList)
set theVariable to item x of theTimeList
if theVariable < item y of TheMinList then set item y of TheMinList to theVariable
if theVariable > item y of TheMaxList then set item y of TheMaxList to theVariable
if item y of TheMinList < theMin then set theMin to item y of TheMinList
if item y of TheMaxList > theMax then set theMax to item y of TheMaxList
set theTotal to theTotal + theVariable
set theCount to theCount + 1
set theFoundFlag to true
exit repeat
end if
end repeat
if not theFoundFlag then
set end of theClientFinalList to item x of theClientList
set end of TheCountList to 1
set theVariable to item x of theTimeList
set end of TheAverageList to theVariable
set end of TheMinList to theVariable
set end of TheMaxList to theVariable
if theVariable < theMin then set theMin to theVariable
if theVariable > theMax then set theMax to theVariable
set theTotal to theTotal + theVariable
set theCount to theCount + 1
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
set theMainData to {}
repeat with x from 1 to count of theClientFinalList
set ClientColumn1 to item x of theClientFinalList
set ClientColumn2 to my CreateTime((item x of TheAverageList) div (item x of TheCountList))
set ClientColumn3 to my CreateTime(item x of TheMinList)
set ClientColumn4 to my CreateTime(item x of TheMaxList)
set ClientColumn5 to item x of TheCountList
set newData to {|Client|:ClientColumn1, |AverageTime|:ClientColumn2, |MinTime|:ClientColumn3, |MaxTime|:ClientColumn4, |NumberJobs|:ClientColumn5}
set end of theMainData to newData
end repeat
try
set theDataSource to NSMutableArray's alloc()'s init()
theDataSource's addObjectsFromArray_(theMainData)
aTableView's reloadData()
set theDataString to "Total of " & theCount & " jobs, for a total time of " & my CreateTime(theTotal) & return & "Av.:" & CreateTime(theTotal div theCount) & " Min.:" & my CreateTime(theMin) & " Max.:" & my CreateTime(theMax)
information's setStringValue_(theDataString)
on error errmsg
display dialog errmsg
end try
end chooseOperator_
-- Set up the second Table
on fetchData()
if DataYear = "Every Year" then
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end repeat
end tell
end if
else
if DataStart = "Mail Manager Folder" then
tell application "Finder"
set temp to every folder of folder (ptd & MMFolder) as list
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
else
tell application "Finder"
set temp to every folder of disk "Jobs" as list
set theOpList to DataOperator
set theZList to {}
set theJobList to {}
repeat with x in temp
if "Ill Interface Data" is in name of x then
set temp to name of x as text
if DataYear = word 4 of temp then
try
set temp to file "IllustratorInterfaceData.dat" of x as text
set temp2 to read file temp as list
repeat with y in temp2
if (item 1 of y is in theOpList) or theOpList = "Every Operator" then
if item 4 of y > 0 then
if item 2 of y = SelectedClient then
set end of theZList to item 5 of y
set end of theJobList to item 6 of y
end if
end if
end if
end repeat
on error errmsg
display dialog errmsg
end try
end if
end if
end repeat
end tell
end if
end if
say 2
set theMainData2 to {}
repeat with x from 1 to count of theZList
say x
set ClientColumn1 to item x of theZList
set ClientColumn2 to item x of theJobList
set newData to {|ZNumber|:ClientColumn1, |JobName|:ClientColumn2}
set end of theMainData2 to newData
end repeat
try
set theDataSource2 to NSMutableArray's alloc()'s init()
theDataSource2's addObjectsFromArray_(theMainData2)
aTableView2's reloadData()
on error errmsg
display dialog errmsg
end try
end fetchData
on CreateTime(thetime)
set thehours to (thetime div 3600)
set thetime to (thetime - (thehours * 3600))
if thehours = 0 then
set thehoursString to ""
else
set thehoursString to thehours & ":"
end if
set theminutes to (thetime div 60)
if theminutes < 10 then
if thehours > 0 then
set theminutes to "0" & theminutes as text
else
set theminutes to " " & theminutes as text
end if
end if
set theSeconds to (thetime - ((thetime div 60) * 60))
if theSeconds < 10 then set theSeconds to "0" & theSeconds as text
set theNewTime to thehoursString & theminutes & ":" & theSeconds
return theNewTime as text
end CreateTime
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
theDataSource's release()
return true
end applicationShouldTerminate_
end script
You need to have a handler that’s called when a row is selected – link it to the table’s Selector in IB. When it gets called, it needs to call the table’s selectedRow(). Something like:
on tableClicked_(sender)
log sender's selectedRow()
-- do your stuff
end tableClicked_