Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

open files with portable notepad++


  • Please log in to reply
16 replies to this topic
viperskunk
  • Guests
  • Last active:
  • Joined: --
Hi folks,
dumb as it may sound, i have only recently started using AHK. and here is my situation.
I have a portable install of Notepad++. The reason why I have this, is to not clutter the context menu, with things like "Open with Notepad ++" etc.
However, sometimes this functionality is useful. For example, I know I can open a .php file in Notepad++, for quick editing, though I still prefer Adobe dreamweaver to remain the default app for opening such files.
So my question is this:

Is there a way where if I select a certain file, any filetype, and press a certain combination of keys, it will open this file with Notepad ++ portable? This is what the context menu does too - provide an almost ubiquitous option to open any file (and if it is an unsupported filetype, the Notepad++ just opens up with a bunch of error and characters.)

In my search I came across this link: http://www.autohotke...topic56962.html
though i don't know how to proceed further.

any help is greatly appreciated.
Thanks

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Hi and welcome to the forum :)

It's very simple: first you set a hotkey ( <!-- m -->http://c.ahk.me/Run<!-- m --> ) the notepad++.exe file with the filename as a parameter, eg.
Run, path\to\notepad++.exe "%file%"

Good Luck! :D

viperskunk
  • Guests
  • Last active:
  • Joined: --

Hi and welcome to the forum :)

It's very simple: first you set a hotkey ( http://c.ahk.me/Run ) the notepad++.exe file with the filename as a parameter, eg.

Run, path\to\notepad++.exe "%file%"

Good Luck! :D


Is the code above all I need? I was trying something like this, but it did not work.
NotepadPlusPlusPath = path\to\Portable\npp.5.9.8.bin\unicode\notepad++.exe
GroupAdd, Explore, ahk_class CabinetWClass         ; Add a class to the group
GroupAdd, Explore, ahk_class ExploreWClass         ; Add a other class to the group
#ifWinActive,ahk_group Explore              ; Set hotkeys to work in explorer only
^!n::
   SelectedFile:=ExplorerGetCurentFolder() "" ExplorerGetFileName()
   SplitPath, SelectedFile,,, OutExt
   run "%NotepadPlusPlusPath%" "%SelectedFile%"
   return
ExplorerGetCurentFolder() {
   if (A_OSVersion="WIN_XP")               ; If we have XP
      ControlGetText Pad, Edit1, A         ; Get the Folder we are in
   else if (A_OSVersion="WIN_VISTA") {      ; If we have vista
      ControlGetText, Pad, toolbarwindow322, ahk_class CabinetWClass   ; Get the folder from the adressbar
      stringreplace, Pad, Pad,% "Address: ",% ""   ; Strip the word Adress: from it
      }
   if (SubStr(Pad, 0, 1)="")            ; If last Char is a \
      StringTrimRight, Pad, Pad,1         ; Remove it
   Return,%Pad%                        ; Return the Currrent folder
   }
ExplorerGetFileName() {
   if (A_OSVersion="WIN_XP")               ; If we have XP
      ControlGet, Selected, List, Selected Col1, SysListView321, A   ; Get the file, Foldername
   else if (A_OSVersion="WIN_VISTA") {      ; If it's Vista
      BlockInput, Mousemove                ; Block mouse movement
      oldclip := ClipboardAll               ; Backup the ClipBoard
      clipboard=                        ; Reset the ClipBoard
      send, ^c                        ; Send the copy command, Ctrl+C
      ClipWait, 0.5                     ; Wait until the ClipBoard contains data
      Selected=%clipboard%               ; Get the data from the ClipBoard
      clipboard := oldclip               ; Restorte the old ClipBoard data
      BlockInput, MousemoveOff            ; Enable mouse movement
      }
   Return,%Selected%                     ; Return the name of the selected item
   }
IsFolder(FileOrFolder) {
   if InStr(FileExist(FileOrFolder), "D")
      return,%true%
   else return,%false%
   }


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
ExplorerGetFileName() returns a full filepath if I'm not mistaken, so you shouldn't use the ExplorerGetCurrentFolder() "\" part.

viperskunk
  • Guests
  • Last active:
  • Joined: --
I tried deleting the
ExplorerGetCurrentFolder() "\"
part, but still no success.

i also tried changing the WIN_VISTA to WIN_7, still no luck.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
This exact code works for me.
#NoEnv
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass

#ifWinActive,ahk_group Explore
^!n::
   ClipSaved := ClipboardAll
   Clipboard := ""
   Send ^c
   ClipWait, 0.5
   file := Clipboard
   Clipboard := ClipSaved
   Run PortableApps\Notepad++Portable\Notepad++Portable.exe "%file%"
return


viperskunk
  • Guests
  • Last active:
  • Joined: --

This exact code works for me.

#NoEnv
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass

#ifWinActive,ahk_group Explore
^!n::
   ClipSaved := ClipboardAll
   Clipboard := ""
   Send ^c
   ClipWait, 0.5
   file := Clipboard
   Clipboard := ClipSaved
   Run PortableApps\Notepad++Portable\Notepad++Portable.exe "%file%"
return


I tried using this too, but still no luck. I don't know what I may be doing wrong. :?

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Perhaps you could post a video using screenr.com, from pasting the AHK code to pressing !^n. It would be helpful to include voice commentary, such as "... and now I press control-alt-n, and... nothing" for any actions which do not generate a visual signal.

viperskunk
  • Guests
  • Last active:
  • Joined: --
This is what my entire ahk script looks like
; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments.  They are not executed.

; This script has a special filename and path because it is automatically
; launched when you run the program directly.  Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it.  You can have as many .ahk
; files as you want, located in any folder.  You can also run more than
; one .ahk file simultaneously and each will get its own tray icon.

; SAMPLE HOTKEYS: Below are two sample hotkeys.  The first is Win+Z and it
; launches a web site in the default browser.  The second is Control+Alt+N
; and it launches a new Notepad window (or activates an existing one).  To
; try out these hotkeys, run AutoHotkey again, which will load this file.

#z::Run C:\Users\Viper\Downloads\Portable\npp.5.9.8.bin\ansi\notepad++

^!n::
IfWinExist Untitled - Notepad
	WinActivate
else
	Run Notepad
return


; Note: From now on whenever you run AutoHotkey directly, this script
; will be loaded.  So feel free to customize it to suit your needs.

; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks.  It also explains more about hotkeys.


;EMPTY TRASH -- WIN+T
#t::

FileRecycleEmpty, C:\

MsgBox, The trash has been taken out.

return



;TOGGLE HIDDEN FOLDERS
; WINDOWS KEY + H TOGGLES HIDDEN FILES
#h::
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
If HiddenFiles_Status = 2 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
Else 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_7")
send, {F5}
Else PostMessage, 0x111, 28931,,, A
Return



;SEARCH GOOGLE FROM ANY APPLICATION
^+c::
{
Send, ^c
Sleep 50
Run, http://www.google.com/search?q=%clipboard%
Return
}


;OPEN WITH NOTEPAD++
#NoEnv
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass

#ifWinActive,ahk_group Explore
^!c::
   ClipSaved := ClipboardAll
   Clipboard := ""
   Send ^c
   ClipWait, 0.5
   file := Clipboard
   Clipboard := ClipSaved
   Run Run C:\Users\viper\Downloads\Portable\npp.5.9.8.bin\ansi\notepad++
 "%file%"
return
When I press the combination for open with notepad++, nothing happens. no popups, no error messages, nothing.

Also I have tried both putting .exe and not at the end of notepad++, still no good.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
This section of your script:
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass
is essential to it working properly, yet those lines are never executed, since they are not part of the Auto-Execute Section. That means that the group Explore is always empty, so the #IfWinActive is always false.

viperskunk
  • Guests
  • Last active:
  • Joined: --

This section of your script:

SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass
is essential to it working properly, yet those lines are never executed, since they are not part of the Auto-Execute Section. That means that the group Explore is always empty, so the #IfWinActive is always false.


So what should I do?

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Read the documentation I linked to you, then you'll know.

viperskunk
  • Guests
  • Last active:
  • Joined: --
Got it working.
Thanks so much for your help!

viperskunk
  • Guests
  • Last active:
  • Joined: --
But now my other hotkeys are not working.

viperskunk
  • Guests
  • Last active:
  • Joined: --
Sorry, but I think I finally sorted everything out. This thread can be marked as solved as far as I am concerned.

Thanks for all the help.