Posts Tagged ‘Scripting’

h1

Creating a Daily Journal in Evernote

15/03/2010

This post has now been migrated to ThoughtAsylum.com.

Follow this link to go directly to the article
.

h1

ENScript – Scripting Evernote in Windows

21/08/2009

This post has now been migrated to ThoughtAsylum.com.

Follow this link to go directly to the article.

h1

Filter files into silo folders

31/07/2009

Recently a number of my friends have hard hard drive failures and have asked me to retrieve data from their hard drives.  I’ve been reasonably successful in each case recovering well over 95% of the data in each case – thanks not to me but the proliferation of free data recovery tools out there on the Internet.

The last one I’ve been working on however has had a particularly mangled folder structure such that a large number of the recovered files haven’t been able to be assigned the correct file name and folder.  The recovery software has auto generated file names and placed them in a single folder … all 245,528 of them.  As you might expect Windows isn’t all that happy with that many files in a single folder when you want to interact with them.

Windows Explorer is incredibly slow to interact with this amount of content and even using SnowBird the speed of access was prohibitive.  I had a need to somehow rearrange the files into some other structure and since the naming is random, the folder structure does not need to be particularly meaningful – just practical to sort through.  Given there was no (free) software up to the job and being the consummate IT support chap I am  I decided to script my way around the problem.

I wrote a VB Script to process the folder of files and to “silo” the files off into groups within other folders.  A couple of constants at the top of the script tell it which folder to process and how many files to put into each folder.  The script then calculates how many folders to create and starts to process them.  I’ve used my generic progress window to show what file is being moved and how far through the process the script is.

The script doesn’t contain anything particularly nifty that hasn’t already been covered in one of my previous VB Script posts, so rather than displaying the source code here I’ve just provided it as a download:

h1

VB Script – Count occurrences in a text string

30/07/2009

This post has now been migrated to ThoughtAsylum.com.

Follow this link to go directly to the article.

h1

Presentations – Keeping your screen active

20/07/2009

Power saving options on computers are something that I personally think are great.  They not only help reduce carbon footprints, but they also help draw out even more life from your laptop battery.   One of the main ways in which this is done (others being things such as disabling hardware) is by having an inactivity option that turns off the screen and the hard disk after a period of inactivity.  Unfortunately there are times when this isn’t something you want.  The primary example of this is when you are giving a presentation.

The typical way of overriding this in Windows is to change what power saving scheme is being used through the Windows control panel or a third party application that links directly to these options.  However sometimes end users don’t have access to this.

This typically occurs where a group policy has been applied to stop users ‘tinkering’ with the power saving schemes.  Users with access can amend or delete power saving schemes which can lead to complications with machines and so it is not that uncommon to restrict access.

Whilst applications such as Microsoft PowerPoint can lead the OS into knowing that it should keep things like monitors on if a presentation is in a browser or some other “power unaware” application, then power saving actions can kick in.

I decided to apply a brute force solution to this by creating an AutoHotKey script to send a key press to the OS at regular intervals.  By default it sends a Shift key press as this is least likely to have any impact on any application, but this can be modified along with the frequency with which it is sent by the use of a settings file.  The settings file also includes an option to choose whether to start sending key presses as soon as it is run.

The code for the script is given at the end of this post, but I have also compiled this into a stand alone executable that you could even pop onto your flash drive if you’re going to be presenting on someone else’s PC.  Similarly you could add it into your start-up group (with it set not to auto start sending key presses) so it is always there when you need it.

The script places a monitor icon in the system tray.  When it is black power saving actions through inactivity will take place.  When it is blue, key presses will be sent.  Right clicking on the icon will display a menu with an override option.  Selecting this option will place a check mark next to it which will set the icon blue and initiate the override mode.  Selecting the option again will uncheck it, set the icon black and turn off the override mode.

Only one setting is available on the settings menu.  This is another check item and determines whether override mode should be enabled immediately when the utility is first started.

The utility looks for a settings file called ActiveDisplay.ini in the folder from which the utility is being run.  If it does not exist, the utility will use its default settings which match the settings given in this example file:

[Settings]
;Set to 1 to enable override mode at start-up and 0 to disable.
EnableOnRun=0
;Specify what characters should be sent.  Use {} for special key strokes
KeyStroke={SHIFT}
;Number of milliseconds between sending the key strokes (120,000 milliseconds : 2 minutes)
Period=120000

If you want to tweak the script to meet your own needs you can get the details below and use your own icons.  If you want to get the compiled version you can download it for free.

#Persistent
#SingleInstance

;Read in settings
iniread, EnableAtStartup, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun, 0
iniread, KeyStroke, %A_ScriptDir%\ActiveDisplay.ini, Settings, KeyStroke, {Shift}
iniread, Period, %A_ScriptDir%\ActiveDisplay.ini, Settings, Period, 120000

;Create the tray menu
menu, tray, add, Override, Override
Menu, SettingsMenu, add, EnabledAtStartup
Menu, tray, add, Settings, :SettingsMenu
menu, tray, add, About
menu, tray, add, Exit
menu, tray, nostandard

;Initialise
;Time to do something that seems crazy - we'll flip these and then call the menu selection routines where it will get flipped back
EnableTimer := EnableAtStartup
EnableAtStartup := Not(EnableAtStartup)
GoSub, EnabledAtStartup
EnableTimer := Not(EnableTimer)
GoSub, Override
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SendKeyStroke:
Send %KeyStroke%
return

Override:
EnableTimer := Not(EnableTimer)
If EnableTimer
{
 menu, tray, Check, Override
 menu, tray, icon, C:\Icons\Monitor On.ico
 menu, tray, tip, Default Power Saving Mode Overridden
 SetTimer, SendKeyStroke, %Period%
}
Else
{
 menu, tray, UnCheck, Override
 menu, tray, icon, C:\Icons\Monitor Off.ico
 menu, tray, tip, Default Power Saving Mode
 SetTimer, SendKeyStroke, Off
}
return

EnabledAtStartup:
EnableAtStartup := Not(EnableAtStartup)
If EnableAtStartup
{
 menu, SettingsMenu, Check, EnabledAtStartup
 iniwrite, 1, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun
}
Else
{
 menu, SettingsMenu, UnCheck, EnabledAtStartup
 iniwrite, 0, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun
}
return

About:
MsgBox, 0, About Active Display, Version 1.0`nCopyright 2009 RebootIT`n`nhttps://flagit.wordpress.com
return

Exit:
ExitApp
h1

A Flexible Progress Window in VBScript

19/07/2009

This post has now been migrated to ThoughtAsylum.com.

Follow this link to go directly to the article.

h1

Shortcuts with VB Script

18/07/2009

Sometimes I need to create shortcuts with VB Script especially if the script is being installed and a shortcut needs to be created to the script.  The code to create a shortcut is quite straight forward,  but the CreateShortcut() function presented here pulls everything together into a single reusable form.  Optional parameters that you don’t want to use can be filled by the use of “NULL” and environment variables can be included in file paths to make this as flexible as possible.

Option Explicit

CreateShortcut "%UserProfile%\SendTo\Test Link.lnk", _
 "C:\Scripts\Test-Script.vbs", NULL, "A test script", NULL, NULL, NULL, NULL, NULL

Function CreateShortcut(p_strShortcutPath, p_strTargetPath, _
 p_strArguments, p_strComment, _
 p_strHotKey, p_strIconPath, p_strIconPosition, _
 p_strWindowStyle, p_strWorkingDirectory)

 'Example Parameters
 'p_strShortcutPath = "%UserProfile%\SendTo\Shortcut to Something"
 'p_strTargetPath = "%PROGRAMFILES%\Somewhere\Something.exe"
 'p_strArguments = "/O"
 'p_strDescription = "Start Something"
 'p_strHotKey = "CTRL+ALT+Q"
 'p_strIconPath = "%PROGRAMFILES%\Somewhere\Something.exe"
 'p_strIconPosition = "3"
 'p_strWindowStyle = "1"
 'p_strWorkingDirectory = "C:\Working\"
 'Use NULL for parameters which are not to be set

 Dim objShell, objShortcut

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objShortcut = objShell.CreateShortcut(objShell.ExpandEnvironmentStrings(p_strShortcutPath))

 If Not isNull(p_strTargetPath) Then
 objShortcut.TargetPath = objShell.ExpandEnvironmentStrings(p_strTargetPath)
 End If

 If Not isNull(p_strArguments) Then
 objShortcut.Arguments = p_strArguments
 End If

 If Not isNull(p_strComment) Then
 objShortcut.Description = p_strComment
 End If

 If Not isNull(p_strHotKey) Then
 objShortcut.HotKey = p_strHotKey
 End If

 If Not isNull(p_strIconPath) Then
 objShortcut.IconLocation = objShell.ExpandEnvironmentStrings(p_strIconPath & ", " & p_strIconPosition)
 End If

 If Not isNull(p_strWindowStyle) Then
 objShortcut.WindowStyle = p_strWindowStyle
 End If

 If Not isNull(p_strWorkingDirectory) Then
 objShortcut.WorkingDirectory = objShell.ExpandEnvironmentStrings(p_strWorkingDirectory)
 End If

 objShortcut.Save
End Function