Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. ## By Cloaky
  2. import win32com.client
  3. import time
  4.  
  5. ## Configurations ##
  6.     #Sound
  7. PlaySounds = True
  8. OnlyWhenSilent = True
  9. SoundCallIncoming = "B:/Others/EventGhost/Sounds/CallIncoming.wav"
  10. SoundNewTextMessage = "B:/Others/EventGhost/Sounds/TextMessage.wav"
  11. SoundNewMail = "B:/Others/EventGhost/Sounds/NewMail.wav"
  12.  
  13.     #iTunes
  14. iTunesSoundVolumeLow = 0.50
  15. iTunesSoundVolumeStep = 5
  16. iTunesSoundVolumeStepDelay = 0.25
  17.  
  18.     #Logs
  19. LogEvents = False
  20. LogDirectory = "B:/Backup/iDevice/Logs/"
  21.  
  22.     #Others
  23. Password = "9999"
  24. EmailSender = "Cloaky"
  25. ForceClose = True
  26. ####################
  27.  
  28. iTunesIsRunning = False
  29. Event = eg.event.suffix
  30. EventPart = Event.split('::')
  31.  
  32. objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
  33. objSWbemServices = objWMIService.ConnectServer('.',"root\cimv2")
  34. colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
  35. for objItem in colItems:
  36.    if objItem.Name == "iTunes.exe":
  37.         iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
  38.         iTunesSoundVolumeLow *= iTunes.SoundVolume
  39.         iTunesIsRunning = True
  40.         break
  41.    
  42. def PlaySound(Sound):
  43.     if PlaySounds == True:      
  44.         if OnlyWhenSilent == False or OnlyWhenSilent == True and EventPart[1] == "Silent":
  45.             LowiTunesVolume()        
  46.             eg.plugins.System.PlaySound(Sound, 1)
  47.             if Sound != SoundCallIncoming:
  48.                 time.sleep(1)
  49.                 RaisingiTunesVolume()
  50.  
  51. def LowiTunesVolume():
  52.     if iTunesIsRunning == True and iTunes.PlayerState != 0:
  53.         eg.globals.iTunesSoundVolume = iTunes.SoundVolume
  54.         while iTunes.SoundVolume > iTunesSoundVolumeLow:
  55.             iTunes.SoundVolume -= iTunesSoundVolumeStep
  56.             time.sleep(iTunesSoundVolumeStepDelay)
  57.        
  58. def RaisingiTunesVolume():
  59.     if iTunesIsRunning == True and iTunes.PlayerState != 0:
  60.         while iTunes.SoundVolume < eg.globals.iTunesSoundVolume:
  61.             iTunes.SoundVolume += iTunesSoundVolumeStep
  62.             time.sleep(iTunesSoundVolumeStepDelay)
  63.  
  64. def LogEvent(Text):
  65.     if LogEvents == True:
  66.         File = open(LogDirectory + eg.Utils.time.strftime('%d-%m-%Y') + ".txt", 'a')
  67.         File.write(eg.Utils.time.strftime('%H:%M:%S - ') + Text + '\n')
  68.         File.close()
  69.        
  70. if EventPart[2] == "CallIncoming":
  71.     print eg.Utils.time.strftime('%H:%M:%S') + " - Incoming Call."
  72.     PlaySound(SoundCallIncoming)
  73.     LogEvent("Incoming Call (" + EventPart[3] + ")")
  74.  
  75. elif EventPart[2] == "CallDialed":
  76.     print eg.Utils.time.strftime('%H:%M:%S') + " - Outgoing Call."
  77.     LowiTunesVolume()
  78.     LogEvent("Outgoing Call (" + EventPart[3] + ")")
  79.  
  80. elif EventPart[2] == "CallDeclined":
  81.     print eg.Utils.time.strftime('%H:%M:%S') + " - Call Declined."
  82.     RaisingiTunesVolume()
  83.     LogEvent("Call Declined (" + EventPart[3] + ")")
  84.  
  85. elif EventPart[2] == "CallAccept":
  86.     print eg.Utils.time.strftime('%H:%M:%S') + " - Call Accepted."
  87.     if iTunesIsRunning == True and iTunes.PlayerState != 0:
  88.         eg.globals.iTunesPaused = 1
  89.         iTunes.Pause()
  90.     else:
  91.         eg.globals.iTunesPaused = 0
  92.     LogEvent("Call Accepted (" + EventPart[3] + ")")
  93.    
  94. elif EventPart[2] == "CallEnd":
  95.     print eg.Utils.time.strftime('%H:%M:%S') + " - Call Ended."
  96.     if iTunesIsRunning == True and eg.globals.iTunesPaused == 1 and iTunes.PlayerState == 0:
  97.         iTunes.Play()
  98.         eg.globals.iTunesPaused = 0
  99.         RaisingiTunesVolume()
  100.     LogEvent("Call Ended (" + EventPart[3] + ")")
  101.  
  102. elif EventPart[2] == "SMS":
  103.     PlaySound(SoundNewTextMessage)
  104.     LogEvent("New Text Message (" + EventPart[3] + ")")
  105.     if EventPart[4] == Password + ":Lock":
  106.         print eg.Utils.time.strftime('%H:%M:%S') + " - New Text Message, Locking Computer."
  107.         eg.plugins.System.LockWorkstation()
  108.     elif EventPart[4] == Password + ":Shut":
  109.         eg.plugins.System.PowerDown(ForceClose)
  110.     elif EventPart[4] == Password + ":Reboot":
  111.         eg.plugins.System.Reboot(ForceClose)
  112.  
  113. elif EventPart[2] == "Mail":
  114.     PlaySound(SoundNewMail)
  115.     LogEvent("New Mail (" + EventPart[3] + ")")
  116.     if EventPart[3] == EmailSender:
  117.         if EventPart[4] == Password + ":Lock":
  118.             print eg.Utils.time.strftime('%H:%M:%S') + " - New Mail, Locking Computer."
  119.             eg.plugins.System.LockWorkstation()
  120.         elif EventPart[4] == Password + ":Shut":
  121.             eg.plugins.System.PowerDown(ForceClose)
  122.         elif EventPart[4] == Password + ":Reboot":
  123.             eg.plugins.System.Reboot(ForceClose)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement