Control your Lync presence during a Pomodoro Sprint using PowerShell

This article is for you Lync-PRO’s out there who want to differentiate yourself from the average Lync user and at the same time want to reach true flow state using the Pomodoro Technique

This article discusses

  • The Pomodoro Technique
  • Flow state by Jason Silva
  • My Lync controlling Pomodoro PowerShell Script
  • The Script

The Pomodoro Technique

PomodoroScott Hanselman explained the Pomodoro Technique in a great way on his PodCast. Pomodoro is about splitting your productive time into intervals of about 25 minutes. During that time you should ignore E-mail, Lync, Twitter, Facebook, Instagram, LinkedIn, news, colleagues and all other elements that could distract you from your trail of thought, your deep dive focus, your flow state.

I have a busy day and it comprise of presentations, meetings, workshops,  customer dialogue, support sessions and talking with colleagues. Sometimes I actually need to deep dive into a problem or produce good documentation, where I have to focus for at least 10 minutes before I reach my flowstate and I need to stay in that flow state as long as possible. My biggest problem is that I am easily distracted and that is why I need to really focus to get real work done :) When I first sit down, I try to do Pomodoro sprints where I try not to get interrupted. When the interval is finished I am available for all the Lync IM’s, mails and everything. This way I may get more quality work done in a short period of time. Read more about Pomodoro here: http://pomodorotechnique.com

Flow State

My goal is to reach a flow state. Jason Silva, my favourite futurist, did a talk on his YouTube channel Shots of Awe. Recommend to get inspired by his talk about the subject

My Lync controlling Pomodoro PowerShell Script

When in a Pomodoro focus session I set do-not-disturb in Lync, disable notifications in Windows 8, and close all web sites that can distract me so I can focus on the work at hand be it an e-mail, document, script or configuration task. I use PowerShell as my Pomodoro timer and with the Lync SDK I am able to start a session, set the correct custom status and know that even if I forget, I will reset my status when my focus session is over.

The function in the script does the following

  • Set the duration of the Pomodoro sprint, usually 25 minutes
  • Import the Lync SDK into PowerShell
  • Delay is where you set the interval the script will update time remaining
  • It plays a start wav file, this could be a 25 minute Pomodoro tick sound
    • I usually just find a cool start tune and then listen to my own music on Spotify or YouTube
  • Then I use custom presence state in my Lync client where I have one state called Pomodoro Focus with do-not-disturb
  • Outlook and other notifications will get suppressed using presentationsettings /start, so no notifications will popup during the sprint
  • After that you have the counter that will count down the remainder of the focus session
    • I publish that in the personal note field of the Lync client, updates every minute with the time for when I will be available again :)
    • The last thirty seconds will display how many seconds are left until full availability

Custat3

  • At the end of the function
    • I play an alarm to notify me that the session is over
    • Reset the Lync presence state
    • Set an appropriate note in the Lync client
    • To make sure I am available again

The Script

Prerequisites

  • Download the Lync SDK
  • In order to avoid having to install visual studio, extract the lyncsdk86.msi from the sdk exe file using winrar or other software
    • The SDK need to match the bitness of your Lync client
  • Go through the script and change the path to where you installed the SDK
    • The script checks to standard paths for Office 2013
  • Running the script from a desktop? Remember to enable PresentationSettings: https://msunified.net/2013/11/25/lock-down-your-lync-status-and-pc-notifications-using-powershell/
  • I use some default wav files to start and end the Pomodoro Sprint, you can change those at the start of the script
  • Now you only need some determination to get some things done using an awesome technique :)

Veiw the script below

#Focus-Pomodoro.ps1
#Last updated: 11.02.2015 By MVP Ståle Hansen (http://msunified.net)
#Pomodoro function by Nathan.Run() http://nathanhoneycutt.net/blog/a-pomodoro-timer-in-powershell/
#Lync Custom states by Jan Egil Ring http://blog.powershell.no/2013/08/08/automating-microsoft-lync-using-windows-powershell/
#Note: for desktops you need to enable presentation settings in order to suppress email alerts, by MVP Robert Sparnaaij: https://msunified.net/2013/11/25/lock-down-your-lync-status-and-pc-notifications-using-powershell/
 
cls
#Add the path to your module and wave file here
$ModulePathISO=(Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath “Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll”)
$ModulePathStream=(Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath “Microsoft Office 2013\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll”)
$StartWave="C:\Windows\Media\Windows Proximity Connection.wav"
$EndWave="C:\Windows\Media\Windows Proximity Notification.wav"
$stop=$False
$errorpref="Continue"
$RunOnce=0
 
#Checking if the files are available
if (Test-Path $ModulePathISO){$ModulePath=$ModulePathISO}
elseif (Test-Path $ModulePathStream){$ModulePath=$ModulePathStream}
else{Write-host SDK dll file not found;Write-Host Exiting script;break}
 
if (!(Test-Path $StartWave)){Write-host Start Wave file not found;$stop="True"}
if (!(Test-Path $EndWave)){Write-host End Wave file not found;$stop="True"}
if ($Stop -eq $True){Read-host "Wav files could not be found, press enter to continue or crl+c to exit";$errorpref="SilentlyContinue"}
 
 Function Publish-LyncContactInformation {
 
    Param (
        # Availability state as int
        [int]$AvailabilityId,
        # ActivityId as int
        [int]$ActivityId,
        # Custom ActivityId as int
        [int]$CustomActivityId,
        # String value to be configured as personal note in the Lync client
        [string]$PersonalNote
    )
    #Importing Lync SDK and create object
    Import-Module -Name $ModulePath
    $Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
    $Self = $Client.Self
    $ContactInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
 
    if ($AvailabilityId) {
        $ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, $AvailabilityId)
    }
 
    if ($CustomActivityId) {
        $ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::CustomActivityId, $CustomActivityId)
    }
 
    if ($PersonalNote) {
        $ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $PersonalNote)
    }
 
    $Publish = $Self.BeginPublishContactInformation($ContactInfo, $null, $null)
    $self.EndPublishContactInformation($Publish)
 
}
 
Function Start-Pomodoro
{
    Param (
        #Duration of your Pomodoro Session
        [int]$Minutes = 25
    )
 
    $seconds = $Minutes*60
    $delay = 1 #seconds between ticks
 
    #Set do-not-disturb Pomodoro Foucs custom presence, where 1 is my pomodoro custom presence state
    Publish-LyncContactInformation -CustomActivityId "1"
 
    #Setting computer to presentation mode, will suppress most types of popups
    presentationsettings /start
 
    #Errorprefernce is set to silent when wav files not present
    $ErrorActionPreference = $errorpref
    #Starting music, remember to change filepath to your wav file
    $player = New-Object System.Media.SoundPlayer $StartWave
    1..2 | %{ $player.Play() ; sleep -m 3400 }
    $ErrorActionPreference = "Continue"
 
    #Counting down to end of Pomodoro
    for($i = $seconds; $i -gt 0; $i = $i - $delay)
    {
         $percentComplete = 100-(($i/$seconds)*100)
         Write-Progress -SecondsRemaining $i `
         -Activity "Pomodoro Focus sessions" `
         -Status "Time remaining:" `
         -PercentComplete $percentComplete
         Start-Sleep -Seconds $delay
 
         #Showing remainder of time in Lync client personal note
         $MinutesRemaining = $i/60
         $MinutesRemaining = [System.Math]::Round($MinutesRemaining, 0)
 
         if ($MinutesRemaining -eq 5 -and $RunOnce -ne 1){
                $RunOnce=1
            }
         elseif ($MinutesRemaining -gt 1){Publish-LyncContactInformation -PersonalNote "Will be available in $MinutesRemaining minutes"}
         elseif ($i -lt 31){Publish-LyncContactInformation -PersonalNote "Will be available in $i seconds"}
         else{Publish-LyncContactInformation -PersonalNote "Will be available in less than a minute"}
 
    }
 
     #Stopping presentation mode to re-enable outlook popups and other notifications
     presentationsettings /stop
 
     #Pomodoro session finished, resetting status and personal note, availabilit 1 will reset the Lync status
     Publish-LyncContactInformation -PersonalNote "Personal Note"
     Publish-LyncContactInformation -Availability "1"
 
     #Errorprefernce is set to silent when wav files not present
     $ErrorActionPreference = $errorpref
     #Playing end of focus session song\alarm, 6 times
     $player = New-Object System.Media.SoundPlayer $EndWave
     1..2 | %{ $player.Play() ; sleep -m 1400 }
     $ErrorActionPreference = "Continue"
 
 }
 
Start-Pomodoro -Minutes 25

5 thoughts on “Control your Lync presence during a Pomodoro Sprint using PowerShell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s