Applescript to create Inbox Items from Adium
I use Adium a lot for communications at work. This inevitably leads to a good amount of action items appearing for me in the chat window. As I could not locate an easy way, through the keyboard, to select the chat history and be able to select all of it and then create an inbox item without a lot of mousing around. This script queries the front chat window, captures the history for that chat for the day and sends it over to Omnifocus as a new inbox item. I have fast script set up so I can just use a hotkey to create an ibox from the chat window. I am posting this as others might find this valuable and if anyone has suggestions/ideas/code to share around this I would appreciate it.
NOTE: I was unable to upload this file, perhaps there is an issue with the file extensions, therefore the script is included in this post. For those of you unfamiliar with AppleScript I can offer the following advice. Set up ApplesScript Directories if you have not done so before: If you have never used AppleScript before then you will likely need to create a few directories first. To do this you can use either Finder or the terminal window. Navigate to your home directory and then to the Library folder Create a new folder here Titled "Scripts" (DO NOT use the quotation marks) Within this folder create a new folder Titled "Applications" Within this folder create a new folder Titled "Adium" from a terminal window: cd ~; mkdir -p Scripts/Applications/Adium Insure Adium is maintaining chat History: Insure Adium is maintaining chat history. This is necessary as this script utilizes the chat history as the source of the information that will be added to the new Inbox Item as a note. Select Adium->Preferences from the menu Select the General section Insure that Log Messages is selected Enable AppleScript in the Menu Bar: Go to Applications->Utilities and open AppleScript Editor. Select AppleScript Editor->Preferences Under General: Select Show Scripts in Menu Bar Sekect Show Computer Scripts Add the Script: If AppleScript editor is not open, navigate to Applications->Utilities and select Applescript Editor this should open a new Window. Paste the script at the end of this post into the open window Select File->Save As and provide a name (I used "New Inbox Item" for this) Note you should place this in the HOME/Library/Scripts/Applications/Adium directory Leave the type as Script You may now close the AppleScript Editor Create an inbox entry: Within adium when you have a chat window open with whatever messages constitute the information you want in your inbox item. go to the menu bar (This will be an icon on the right side of the top menu bar) You should see the name of the script from the previous step ('New Inbox Item' if you used the recommended name). Click this. You should hear a beep and you should see a new item in your inbox from this chat session What the script does: This script gets the front window/chat from Adium and determines the account (your account) and the person you are chatting with. This script gets the current date/time This script goes to the chat history directory and looks for directories for the current date from this account and the person you are chatting with This script parses the chat history files (in oreder based on time) and create a new inbox entry What the script lacks: The script currently uses the alias of the person you are chatting with and the current date/timestamp from the last messages as the name of the new inbox item. The date/time is not parsed into a pretty format The parsing code for the chat history is very simplistic and hard coded to expect a simple <Message> entry The likelihood that this might have problems with date/time transitions (such as near midnight) is definitely possible The likelihood that the message format in the chat history XML is more flexible than this script expects is very likely (and hence an error would be returned) The likelihood that a laungauge outside of american, southern to be explicit, might cause this to fail exists Well that's a lot of potential's. It does, however, work in the very limited testing that I have done. I will, open a post, attempt to rectify issues/improve this within my means. If you include a URL where good doc on Applescript/Adium/etc that would be appreciated. Also, and more important, post a copy of your chat history file(s) for the user/date in question. You can remove all message text/replace with characters (in the same locale) so that you are not posting anything confidential/private. Here is the script: -- A very simple way to transform the current date into YYYY-MM-DD format on date_format(old_date) set {year:y, month:m, day:d} to date old_date set tm to m as integer set dy to d as integer if dy < 10 then set ds to "0" & dy as string else set ds to dy as string end if if tm < 10 then set ts to "0" & tm as string else set ts to tm as string end if set result to ((y as string) & "-" & ts & "-" & ds) return result end date_format -- Determine the current date set cleandate to date_format(date string of (current date)) -- Establish an empty buffer for the note text set outputString to "" -- Get Adium to tell us who we are chatting with, the account, etc. tell application "Adium" set theChat to the active chat set theName to the name of theChat set theAccount to the account of theChat set theAccountName to the name of theAccount set theDisplayName to the display name of theAccount set theService to the service of theAccount set theServiceName to the name of theService end tell -- The work Dir is based on the service, account (us) and who we are chatting with set theworkDir to "Library:Application Support:Adium 2.0:Users:Default:Logs:" & theServiceName & "." & theAccountName & ":" & theName -- Get the Home Directory (Likely easier ways to accomplish) tell application "Finder" set startingPath to path to home folder end tell -- Now we have the full path to use with Finder set theDirectory to (startingPath as string) & theworkDir -- Now get the finder to get the list of directories (and therefore files) tell application "Finder" set itemGroup to sort (get every file of the folder theDirectory whose name contains cleandate) by creation date set startNum to length of itemGroup set outputString to "" set correctaliasname to "" repeat with theIncrementValue from length of itemGroup to 1 by -1 set groupItem to item theIncrementValue of itemGroup set itemname to the name of groupItem set theFullDirectory to theDirectory & ":" & itemname set Pos to length of itemname set theShortName to characters 1 thru (Pos - 7) of itemname as string set theFileName to theFullDirectory & ":" & theShortName & "xml" tell application "System Events" set xml_data to contents of XML file theFileName --the_file tell xml_data to set level_1 to XML element 1 tell xml_data to set level_2 to XML elements of level_1 tell xml_data to set data_count to count level_1 tell xml_data to set data_count2 to count level_2 repeat with theElementValue from 1 to data_count2 tell xml_data to set work_element to XML element theElementValue of level_1 tell current application if name of work_element contains "message" then tell xml_data to set aliasname to «class valL» of «class xmla» "alias" of work_element tell xml_data to set sendername to «class valL» of «class xmla» "sender" of work_element tell xml_data to set timename to «class valL» of «class xmla» "time" of work_element tell xml_data to set gomore to the count of every «class xmle» of work_element tell xml_data to set work_elementdiv to «class xmle» 1 of work_element tell xml_data to set gomore2 to the count of every «class xmle» of work_elementdiv if gomore2 > 0 then tell xml_data to set work_elementspan to «class xmle» 1 of work_elementdiv set outputString to outputString & " " & timename & " - (" & aliasname & ") from (" & sendername & ") :: " & «class valL» of work_elementspan else set outputString to outputString & " " & timename & " - (" & aliasname & ") from (" & sendername & ") :: " & «class valL» of work_elementdiv end if end if end tell end repeat end tell end repeat end tell set taskName to theName & " - " & timename tell application "OmniFocus" tell quick entry activate open set newTask to make new inbox task with properties {name:taskName, note:outputString} select {inbox task 1} beep save close end tell end tell tell application "Adium" activate end tell |
Wow, that's pretty cool, Russ - thanks for uploading this! I'm not aware of a file naming restriction, but I'll poke around and see if I can find a setting to tweak.
|
All times are GMT -8. The time now is 10:29 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.