ac’tivAid

A while back – January, if I am not mistaken – a colleague of mine saw some of my AHK scripts. Upon seeing this, he showed me a little portable app he uses to get the same results.

That’s how I learned about ac’tivAid. It is a framework for AHK scripts created by Wolfgang Reszel
for the german PC magazine c’t. The official article is on their website; where you can download the app (here is the direct link for non german speaks: link).

This framework comes by default with quite a lot of extensions (scripts). And some pretty neat ones for that matter. I have running right now: Continue reading

Dynamic Snips v2

Dynamic Snips v1

Description

  • ChangeLog
    • Rewriting so it is an extension for the ac’tivAid
    • Search engines can be edited
    • Internet Browser can be edited
    • Settings are saved in a INI-File and can be edited using the GUI
    • Icons can be customized
  • To Do

If you have more suggestions or requests, please contact me or leave a comment.

If you need some help installing or understanding how extension for ac’tivAid work, please check this article: How to add new extensions to ac’tivAid.

Donwload:

; -----------------------------------------------------------------------------
; #############################################################################
; -----------------------------------------------------------------------------
; Name:               Dynamic Snips
; -----------------------------------------------------------------------------
; Prefix:             snip_
; Version:            2.0
; Date:               2013-04-05 09:06:28
; Author:             Lipkau, Oliver
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; === Initialisation ==========================================================
; -----------------------------------------------------------------------------

; Initialisierungsroutine, welche beim Start von ac'tivAid aufgerufen wird.
init_DynamicSnips:

   ; * Das verwendete eindeutige Präfix ohne Unterstrich
   Prefix = snip
   ; * Der Name der Erweiterung ohne Leerzeichen und Sonderzeichen
   %Prefix%_ScriptName    = DynamicSnips
   ; * Die Version der Erweiterung
   %Prefix%_ScriptVersion = 2.0
   ; Der Autor der Erweiterung
   %Prefix%_Author        = oliver@lipkau.net
   ; Erweiterungen, welche für diese Erweiterung installiert sein müssen (kommasepariert, ohne Leerzeichen)
   RequireExtensions      =
   #include %A_ScriptDir%\Library\MI.ahk
   
   ; Wenn 1, dann gibt's im 'Pfeil'-Menü einen Eintrag, dass Einstellungen hinzugeladen werden können
   AddSettings_DynamicSnips = 1
   ; Wenn eine eigene Konfigurations-Datei statt ac'tivAid.ini verwendet wird, muss hier der relative Pfad angegeben werden
   ConfigFile_DynamicSnips = ; %SettingsDir%\datei.ini

   ; Durch setzen der folgenden drei Variablen, kümmert sich ac'tivAid automatisch um ein Tastaturkürzel
   ; für die Erweiterung und fügt auch automatisch ein Tastaturkürzel-Schaltfläche zum Konfigurationsdialog hinzu
   CustomHotkey_DynamicSnips = 1           ; automatisches benutzerdefinierbares Tastaturkürzel? (1 = ja)
   Hotkey_DynamicSnips       = #w           ; Standard-Hotkey
   HotkeyPrefix_DynamicSnips =            ; Präfix, welches vor immer vor dem Tastaturkürzel gesetzt wird
                                                ; in diesem Fall sorgt es dafür, dass das Tastaturkürzel durchgeschleift wird.

   HideSettings = 0                             ; Wenn 1, dann bekommt die Erweiterung keinen Eintrag im Konfigurationsdialog
   EnableTray_DynamicSnips   =            ; Soll eine Erweiterung nicht im Tray-Menü aufgeführt werden, muss der Wert 0 betragen

   DisableIfCompiled_DynamicSnips =       ; Wenn 1, lässt sich die Erweiterung in kompilierter Form nicht de-/aktivieren

   ; CreateGuiID("DynamicSnips")  ; nächste freie GUI-ID in %GuiID_Dynamic Snips% ablegen und Close/Escape-Label
                                        ; registrieren (z.B. Dynamic SnipsGuiClose statt 5GuiClose)
                                        ; Zugriff auf die GUI-ID vor dem Aufbau der Gui über: GuiDefault("Dynamic Snips")

   IconFile_On_DynamicSnips  = %A_ScriptDir%\icons\ol_DynamicSnips.ico
   IconPos_On_DynamicSnips   = 1
   IconFile_Off_DynamicSnips = 
   IconPos_Off_DynamicSnips  = 
   
   ; Path to the directory where the structure for the menu should be located
   ; If no full path is given, it will be interpreted as relative to the scripts location

   ; File extension for the text files
   ; The dot (.) should not be included
   snip_ext = snip   


   ; Sprachabhängige Variablen
   If Lng = 07  ; = Deutsch (0407, 0807, 0c07 ...)
   {
      MenuName                      = %snip_ScriptName%
      Description                   = Kurze Beschreibung, was die Erweiterung so kann
      lng_snip_assfile              = .snip Dateien sollen mit Notepad geöffnet werden
      lng_snip_assfile_button       = Ja!
      lng_snip_adminerror_title     = Admin Rechte sind notwendig
      lng_snip_adminerror_text      = Damit die Registry geändert werden kann braucht das Programm Admin Rechte
      lng_snip_importerror_title    = Fehler
      lng_snip_importerror_text     = Programm hat nicht die Verknüpfung der .snip Dateien machen können
      lng_snip_importsucess_title   = Erfolg
      lng_snip_importsucess_text    = Programm hat die Verknüpfung der .snip Dateien erfolgreich machen können
      lng_snip_opendir_button       = Snip-Ordner öffner
      lng_snip_snip_folder          = Snip-Ordner Pfad
   }
   else        ; = Alternativ-Sprache (wenn nicht Deutsch und keine language.ini vorhanden)
   {
      MenuName                      = %snip_ScriptName%
      Description                   = Kurze Beschreibung, was die Erweiterung so kann
      lng_snip_assfile              = Assosiate .snip file extension to Notepad
      lng_snip_assfile_button       = Do it!
      lng_snip_adminerror_title     = Need Administrative Permissions
      lng_snip_adminerror_text      = In order to  modify the Windows Registry this program needs administrative rights
      lng_snip_importerror_title    = File Association Failed
      lng_snip_importerror_text     = Failed to associated .snip files to notepad.exe
      lng_snip_importsucess_title   = Success
      lng_snip_importsucess_text    = Successfully associated .snip files to notepad.exe
      lng_snip_opendir_button       = Open Snip-Folder
      lng_snip_snip_folder          = Snip-Ordner Path

   }

   ; Hier folgt nun z.B. das Einlesen der Konfigurationswerte aus der INI-Datei
   ; Die zusätzlichen Unterordner aus der INI-Datei auslesen
   snip_DefaultPath = %A_ScriptDir%\extensions\Dynamic Snips
   IniRead, snip_path, %ConfigFile%, %snip_ScriptName%, Path, %snip_DefaultPath%
   ;~ SplitPath, A_ScriptFullPath, snip_ScriptName, ScriptDir, , , ScriptDrive
   
   ;enbale environment variables:
   snip_path_run := snip_cleanVariables(snip_path)
   
   If (!FileExist(snip_path_run))
      snip_createExamples(snip_path_run)
   
   Menu, snip_Root, Add,     %snip_ScriptName% %snip_ScriptVersion%, noOp
   snip_h_menu := MI_GetMenuHandle("snip_Root")
   MI_SetMenuStyle(snip_h_menu, 0x4000000)
   
   WS_EX_APPWINDOW = 0x40000
   WS_EX_TOOLWINDOW = 0x80
    
   Menu, snip_Root, default, %snip_ScriptName% %snip_ScriptVersion%      
   _icon  := MI_ExtractIcon(A_ScriptDir . "\icons\ol_DynamicSnips.ico", 1, 16)
   MI_SetMenuItemIcon(snip_h_menu, 0, _icon,1,16)
   Menu, snip_Root, Add
   
   i=1
   Loop, %snip_path_run%\*.*,1, 0
   {
      snip_LongFileName := A_LoopFileLongPath
      RegExMatch(snip_LongFileName, "^.*\\(.+?)$", regexout)
      catname := regexout1
      outcatname := RegExReplace(catname, " ", "_")
      AttributeString := FileExist(snip_LongFileName)
      IfInString, AttributeString, D
      {
         Menu, %outcatname%, Add
         Menu, %outcatname%, DeleteAll
          
         Menu, %outcatname%, Add, %catname%, noOp
         Menu, %outcatname%, Disable, %catname%
         Menu, %outcatname%, Add 

         Loop, %snip_path_run%\%catname%\*.%snip_ext%, 1, 0
         {
            SplitPath, A_LoopFileLongPath, snip_FileName, snip_FileDir, snip_FileExtension, snip_FileNameNoExt, snip_FileDrive
            Menu, %outcatname%, Add, %snip_FileNameNoExt%                , snip_ScriptOpen
         }
         Menu, snip_Root, Add, &%i%  %catname%, :%outcatname%
         snip_hs_menu := MI_GetMenuHandle(outcatname)
         iconpath := snip_LongFileName . "\icon.ico"
         if (FileExist(iconpath)){
            _icon := MI_ExtractIcon(iconpath, 1, 16)
            MI_SetMenuItemIcon(snip_hs_menu, 1, _icon,1,16)
            MI_SetMenuItemIcon(snip_h_menu, %i%+2, _icon,1,16)
         }
         i++
      }
   }
   Menu, snip_Root, Add
   Loop, %snip_path_run%\*.snip, 0, 0
   {
      SplitPath, A_LoopFileName, snip_FileName, snip_FileDir, snip_FileExtension, snip_FileNameNoExt, snip_FileDrive
      Menu, snip_Root, Add, %snip_FileNameNoExt%                , snip_ScriptOpen
   }

   MI_SetMenuStyle(snip_h_menu, 0x04000000) ; MNS_CHECKORBMP

Return

; Die folgende Routine enthält alle Befehle, welche dazu nötig sind den Konfigurationsdialog zu ergänzen
; Das erste GUI-Element sollte immer mit "XS+10 Y+5" positioniert werden, wobei der Y-Wert ggf.
; auch angepasster werden kann.
SettingsGui_DynamicSnips:
   Gui, Add, Text, -Wrap xs+10 y+10, %lng_snip_snip_folder%
   Gui, Add, Edit, xp+200 gsub_CheckIfSettingsChanged vsnip_path, %snip_path%
   Gui, Add, Text, -Wrap xs+10 y+10, %lng_snip_assfile%
   Gui, Add, Button, xp+250 gsub_snip_AssociateFile, %lng_snip_assfile_button%
   Gui, Add, Button, -Wrap xs+10 y+10 gsub_snip_OpenDir, %lng_snip_opendir_button%
Return

; wird aufgerufen, wenn im Konfigurationsdialog OK oder Übernehmen angeklickt wird
SaveSettings_DynamicSnips:
   IniWrite, %snip_path%, %ConfigFile%, %snip_ScriptName%, Path
   ; Wenn es nötig ist, dass ac'tivAid nach dem Speichern der Einstellungen neu geladen werden muss, kann man Reload auf 1 setzen
   ; Reload = 1
Return

; Wird aufgerufen, wenn Einstellungen über das 'Pfeil'-Menü hinzugefügt werden, ist nur notwendig wenn AddSettings_Dynamic Snips = 1
AddSettings_DynamicSnips:
Return

; wird beim Abbrechen des Konfigurationsdialogs aufgerufen
CancelSettings_DynamicSnips:
Return

; wird beim Aktivieren der Erweiterung aufgerufen
DoEnable_DynamicSnips:
   ; func_HotkeyEnable("snip_HOTKEYNAME")
Return

; wird beim Deaktivieren der Erweiterung und auch vor dem Speichern der Einstellungen aufgerufen
DoDisable_DynamicSnips:
   ; func_HotkeyDisable("snip_HOTKEYNAME")
Return

; wird aufgerufen, wenn der Anwender die Erweiterung auf die Standard-Einstellungen zurücksetzt
DefaultSettings_DynamicSnips:
Return

; wird aufgerufen, wenn ac'tivAid beendet oder neu geladen wird.
OnExitAndReload_DynamicSnips:
Return

; -----------------------------------------------------------------------------
; === Hotkeys =================================================================
; -----------------------------------------------------------------------------

; Unterroutine für das automatische Tastaturkürzel
sub_Hotkey_DynamicSnips:
   MI_ShowMenu(snip_h_menu)
return

; -----------------------------------------------------------------------------
; === Subroutines =============================================================
; -----------------------------------------------------------------------------

sub_snip_AssociateFile:
   Random, random
   tmpfile := A_Temp . "\" . random . "snipfile.reg"
   
   FileAppend, Windows Registry Editor Version 5.00, %tmpfile%
   
   FileAppend,
   (
[HKEY_CURRENT_USER\Software\Classes\.snip]
@="snip_auto_file"
"Content Type"="text/plain"
"PerceivedType"="text"

[HKEY_CURRENT_USER\Software\Classes\.snip\OpenWithProgids]
"snip_auto_file"=""

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file]
@="Dynamic Snip file"
"PerceivedType"="text"

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file\shell]

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file\shell\edit]

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file\shell\edit\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file\shell\open]

[HKEY_CURRENT_USER\Software\Classes\snip_auto_file\shell\open\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.snip]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.snip\OpenWithList]
"a"="Notepad.Exe"
"MRUList"="a"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.snip\OpenWithProgids]
"snip_file"=hex(0):
"snip_auto_file"=hex(0):

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.snip\UserChoice]
"Progid"="snip_file"
   ), %tmpfile%
   
   ;~ |__RUNNS_AS_ADMIN_______________|
   if (A_IsAdmin) {
      FileAppend,
      (
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\snip_auto_file]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\snip_auto_file\DefaultIcon]
@="%SystemRoot%\system32\imageres.dll,97"

      ), %tmpfile%
   }
   
   RunWait, %comspec% /c reg import "%tmpfile%", , Hide ErrorLevel
   if (errorlevel)
      MsgBox, 48, %lng_snip_importerror_title%, %lng_snip_importerror_text%
   FileDelete, %tmpfile%
   MsgBox, 0, %lng_snip_importsucess_title%, %lng_snip_importsucess_text%, 4
Return

snip_createExamples(snip_path_run)
{
   FileCreateDir, %snip_path_run%
   FileCreateDir, %snip_path_run%\examples.programming
   FileCreateDir, %snip_path_run%\examples.email text
   
   FileInstall, icon.example.programming.ico, %snip_path_run%\examples.programming\icon.ico
   FileInstall, icon.example.text.ico, %snip_path_run%\examples.email text\icon.ico
   
   FileAppend,
   (
john.doe@siemens.com
   ), %snip_path_run%\example.username_email.snip
   FileAppend,
   (
Z00XXXXXXXX
   ), %snip_path_run%\example.username_gid.snip
   FileAppend,
   (
Hello ,

	
   ), %snip_path_run%\examples.email text\example.greeting.snip
   FileAppend,
   (
With kind regards

------------------------
email@email.com
tel: +1 23 45678
   ), %snip_path_run%\examples.email text\example.signature.snip
   FileAppend,
   (
try
 {      }
catch [system.exception]
 {      }
finally
 {      }
   ), %snip_path_run%\examples.programming\example.try_catch_finally.snip
   FileAppend,
   (
try
 {      }
catch [system.exception]
 {      }
   ), %snip_path_run%\examples.programming\example.try_catch.snip
   FileAppend,
   (
switch ($x)
{
 1 {         }
 2 {         }
 Default {   } 
}
   ), %snip_path_run%\examples.programming\example.switch.snip
   FileAppend,
   (
if($x -gt $y) 
  {         }
elseif($y -gt $x)
  {         }
else
  {         }
   ), %snip_path_run%\examples.programming\example.if_elseif_else.snip
   FileAppend,
   (
if($x -gt $y) 
  {         }
else
  {         }
   ), %snip_path_run%\examples.programming\example.if_else.snip
   FileAppend,
   (
if($x -gt $y) 
  {         }
   ), %snip_path_run%\examples.programming\example.if.snip
   FileAppend,
   (
function name
{
 Param( )
 
}
   ), %snip_path_run%\examples.programming\example.function.snip
   FileAppend,
   (
Foreach($x in $y)
 {              }
   ), %snip_path_run%\examples.programming\example.foreach.snip
   FileAppend,
   (
Do
 {

 } While (  )
   ), %snip_path_run%\examples.programming\example.do_while.snip
   FileAppend,
   (
Do
 {

 } Until (  )
   ), %snip_path_run%\examples.programming\example.do_until.snip
   FileAppend,
   (
while($x -lt $y)
 {
  $x
  $x++
 }
   ), %snip_path_run%\examples.programming\example.while.snip
   return
}

noOp:
   noOp := true
return

snip_ScriptOpen:
   menu := RegExReplace(A_ThisMenu, "_", " ")
   item := A_ThisMenuItem
   if (menu == "snip Root")
      snip = %item%.%snip_ext%
   else
      snip = %menu%\%item%.%snip_ext%
   file = %snip_path_run%\%snip%
   if (!FileExist(file)){
      MsgBox, 48, File not found, The file requested could not be found.`nFile path: %file%
      return
   }
   
   FileRead, content, %file%
   Clipboard := content
   Send, ^v
return

sub_snip_OpenDir:
   run, explorer.exe %snip_path_run%
return

snip_cleanVariables(snip_temp_in) {
   if (RegExMatch(snip_temp_in, "%(.+)%", SubPart)) {
      if (Instr(SubPart1,"A_")) {
         snip_d_path := %SubPart1%
         StringReplace, snip_temp_in, snip_temp_in, `%%SubPart1%`% , %snip_d_path%
      } else {
         EnvGet, snip_temp_env, %SubPart1%
         StringReplace, snip_temp_in, snip_temp_in, `%%SubPart1%`% , %snip_temp_env%
      }
   }
   return %snip_temp_in%
}

OmniContextMenu v3

It’s been only a few days since I wrote about a script I wrote “OmniContextMenu v2“.
And as I mentioned somewhere in there, I got some feedback from friends and did some working on the code.
So here it is: Version 3.0

Description

OmniContextMenu is a script with a customization menu that opens with a Ctrl+RightMouse click on a select text. In this menu you will find some search engines (i.e.: Google, Goolge Images, Dictionaries, or whatever you choose to add). When clicking on an menu item, the script will start a new windows/tab on the browser of your choice searching for the selected text in the selected search engine.

Continue reading

OmniContextMenu

Quite some time ago (2008, if I am not mistaken) derRaphael, a well-known scripter on the german AHK forum, wrote a script inspired by the Firefox addon Ubiquity. He named it dR’s OCM (OmniContextMenu).

Unfortuantly his original code is no longer available on the internet.
But in October I remembered this code of his and found a backup somewhere in my storage.
I took a look at it and decided to use it again. Since this meant some updates in the APIs and his code, I made a version 2.0.
Continue reading

Dynamic Snips

Recently I had an idea:
I was using Ed Wilson’s Code Snippets (which he introduced in his article Add Code Snippets to Your Script by Using the PowerShell ISE) a lot for powershell when writing scripts in PowerShell ISE. However I missed this when writing other things (i.e.: AHK scripts, ABAP reports, e-mails, a.s.o.).

I remembered Lexikos’ AHKControl back from 2008 and thought I could combine both ideas.

Continue reading