DreamCheekyLED_Outlook.ps1 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Description: Dream Cheeky LED Powershell Outlook Script
  2. # Author: Greg Bray
  3. # Date: 8/9/2012
  4. # License: Apache 2.0
  5. if(([appdomain]::currentdomain.getassemblies() | Where {$_ -match "DreamCheekyLED"}) -eq $null){
  6. Write-Host "Loading DreamCheekyLED Assembly"
  7. $assembly = [Reflection.Assembly]::LoadFile("D:\Projects\DreamCheekyUSB\DreamCheekyLED\bin\release\DreamCheekyLED.exe")
  8. }
  9. #List all USB devices with VID=0x1D34
  10. #[HidLibrary.HidDevices]::Enumerate() | where { $_.Attributes.VendorHexId -eq "0x1D34" }| ft isConnected,isOpen,Description -AutoSize
  11. #Initialize led object
  12. if($led -eq $null){
  13. Write-Host "Initializing LED object"
  14. $led = New-Object DreamCheekyUSB.DreamCheekyLED -ArgumentList @(0)
  15. #$led = New-Object DreamCheekyUSB.DreamCheekyLED -ArgumentList @(0x1D34,0x0004,0) #Specify VID,PID,DeviceIndex
  16. #Issues with calling the device path constructor from powershell. Error was New-Object : Index was outside the bounds of the array.
  17. #This finally worked:
  18. #$argArray = New-Object string[] 1
  19. #$argArray[0] = '\\?\hid#vid_1d34&pid_0004#6&1067c3dc&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'
  20. #$led = New-Object -TypeName DreamCheekyUSB.DreamCheekyLED (,$argArray)
  21. #This also worked:
  22. #$led = New-Object -TypeName DreamCheekyUSB.DreamCheekyLED (,'\\?\hid#vid_1d34&pid_0004#7&451d3da&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}')
  23. } else {
  24. #TODO: Make sure it is connected and working!
  25. }
  26. #Test LED:
  27. if(!$led.Test()){
  28. write-error "Testing LED failed!"
  29. }
  30. #Setup Outlook COM object. TODO: Check for errors (Outlook not open, etc). See security issues: http://www.outlookcode.com/article.aspx?id=52 and http://technet.microsoft.com/en-us/library/ff657852.aspx
  31. #Alternative: http://psoutlookmanager.codeplex.com/
  32. #Folder format: $ns.Folders.Item("Personal Folders - Old").Folders.Item("Inbox")
  33. Write-Host "Creating Outlook COM object"
  34. $ol = New-Object -Com Outlook.Application
  35. $ns = $ol.GetNameSpace('MAPI')
  36. $mail1 = $ns.Stores[1]
  37. $mail2 = $ns.Stores[2]
  38. $inbox1 = $mail1.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
  39. $inbox2 = $mail2.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
  40. #TODO: store state so that you can cycle colors and support multiple accounts.
  41. #TODO: extract name of account and set color based on name not order, which can change
  42. Write-Host "Starting mail checking loop"
  43. while($true){
  44. if($inbox1.UnReadItemCount -gt 0){
  45. Write-Host "New mail (Account 1)! Count =" ($inbox1.UnReadItemCount)
  46. $led.Blink([System.Drawing.Color]::Magenta,$inbox1.UnReadItemCount,500) | Out-Null;
  47. $led.FadeIn([System.Drawing.Color]::Magenta,2000) | Out-Null;
  48. } elseif($inbox2.UnReadItemCount -gt 0){
  49. Write-Host "New mail (Account 2)! Count =" ($inbox2.UnReadItemCount)
  50. $led.Blink([System.Drawing.Color]::Navy,$inbox2.UnReadItemCount,500) | Out-Null;
  51. $led.FadeIn([System.Drawing.Color]::Navy,2000) | Out-Null;
  52. } else {
  53. Write-Host "No mail waiting..."
  54. $led.Off() | Out-Null
  55. }
  56. Start-Sleep -Seconds 15
  57. }