OK, here's a script that will save the data to a tab delimited text file
(it's easier to write than a CSV file and Numbers doesn't handle CSV properly
- not with embedded commas or returns in the data). It will also open the
said file in Numbers for you automatically (you can still open the saved data
in excel in parallels as well, if you like).
If you don't want Numbers to open the file automatically, just leave out the
last four lines of code.
-- Export Selected Events v1.1 (2009-01-04)
-- an applescript by Barry Wainwright <mailto:
[email protected]>
-- exports certain data from selected events to an excel spreadsheet.
-- Written in response to a user request
-- This script released under a Creative Commons Attribution,
-- NonCommercial, ShareAlike 2.0 England & Wales License.
-- see <
http://creativecommons.org/licenses/by-nc-sa/2.0/uk/>
-- for full details
-- Version History
-- v1.1 2009-01-04 - changed script to write to TDT file instead of
-- putting data straight into excel
-- v1.0 2009-01-03 - First Release
tell application "Microsoft Entourage"
try
set theSelection to selection
if class of theSelection is list then
set itemClass to class of item 1 of theSelection
else
set itemClass to class of theSelection
end if
if itemClass ≠event then error -99
on error errMsg number errNum
display dialog ¬
"your selection does not contain any events" buttons {"OK"} default
button 1
return
end try
set exportList to {"Name" & tab & "Start Date" & tab ¬
& "Start Time" & tab & "End Time" & tab & "Category"}
set {oldTIDS, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, {", "}}
repeat with anEvent in theSelection
set eventData to {mysub:subject, myST:start time, myET:end time,
myCat:category} ¬
of anEvent
set myStartDate to short date string of myST of eventData
set myStartTime to time string of myST of eventData
set myEndTime to time string of myET of eventData
set catNames to {}
repeat with aCat in myCat of eventData
copy name of aCat to end of catNames
end repeat
set {oldTIDS, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, {", "}}
set myCatNames to catNames as text
set AppleScript's text item delimiters to oldTIDS
set dataLine to mysub of eventData & tab & myStartDate ¬
& tab & myStartTime & tab & myEndTime & tab & myCatNames
copy dataLine to end of exportList
end repeat
end tell
set outFile to choose file name default location (path to desktop) as alias ¬
default name "Event Export " & short date string of (current date) & ¬
".txt" with prompt "Please choose a location to save the data:"
try
set theFile to open for access outFile with write permission
on error
try
close access outFile
end try
end try
set {oldTIDS, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, {return}}
write (exportList as text) to theFile
set AppleScript's text item delimiters to oldTIDS
close access theFile
-- Delete the following code if you don't want
-- Numbers to open the file automatically
tell application "Numbers"
activate
open outFile
end tell