#NoTrayIcon
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
ClipSaved := ClipboardAll
Clipboard =
Send, ^c
ClipWait, 0.5
Path_ = %Clipboard%
Loop, Parse, Path_, `n, `r
{
Path_ := A_LoopField
Break
}
If Path_ Contains .ahk,.bat,.css,.ini,.inf,.js,.jsx,.reg,.xml,.bak,.cfg,.nfo
{
SplitPath, Path_, name
FileOpen = %name% - Notepad2
SetTitleMatchMode, 3
If not WinExist( FileOpen )
{
Run, Notepad2.exe %Path_%
}
Else
WinActivate
Clipboard := ClipSaved
}
Else
Clipboard := ClipSaved
Run, Notepad2.exe %1 ; <-- ???
return
ExitApp
The %1 variable in AHK ?
Started by
Guest
, Jul 14 2011 11:22 AM
3 replies to this topic
#1
Guests
Posted 14 July 2011 - 11:22 AM
I was thinking of using the code below, compiled and added in registry instead of Notepad2.exe for the key "Edit", but I realized that atleast one other way(tray contextmenu) doesnt work if I do it like that.. Is there a way to pass the original path variable %1 if there isnt an opened instance already? Or maybe a better aproach of doing this?
#2
Posted 14 July 2011 - 01:30 PM
Run, Notepad2.exe %1%*untested, but should work*
Read on command line parameters in the help file.
#3
Posted 14 July 2011 - 04:57 PM
What are you trying to do?
This script copied some selected text into the clipboard, then attempts to see if it is a .ahk, .txt, etc file, and if so then check if it is open in Notepad2, and if not then open it in Notepad2.
The last if statement says "if it wasn't one of the ahk, .txt, etc types, then open it in Notepad2 anyway"... which begs the question: why are you trying to detect that in the first place?
To answer your question, the following should do it (as surely Path_ is your original "copied" path), but why would you do that?
Also, if you are trying to open a path from the command line, or from a path in the clipboard (or any other type of file really), you should check that they exist first before trying to open them with Notepad2.
This script copied some selected text into the clipboard, then attempts to see if it is a .ahk, .txt, etc file, and if so then check if it is open in Notepad2, and if not then open it in Notepad2.
The last if statement says "if it wasn't one of the ahk, .txt, etc types, then open it in Notepad2 anyway"... which begs the question: why are you trying to detect that in the first place?
To answer your question, the following should do it (as surely Path_ is your original "copied" path), but why would you do that?
Run, Notepad2.exe %Path_%
Also, if you are trying to open a path from the command line, or from a path in the clipboard (or any other type of file really), you should check that they exist first before trying to open them with Notepad2.
#4
Guests
Posted 14 July 2011 - 10:25 PM
What are you trying to do?
The Idea was to prevent overwriting if I by misstake opened more than 1 instance of the same file. It happens sometimes for me and its very annoying.
which begs the question: why are you trying to detect that in the first place?
Its kind of unlikely but if I have a partial titlematch It would bring up the wrong file ..wasnt too worried about that, just thought it wouldnt hurt?
The reason Notepad2 is launched anyway if not a match is because that is whats suppose to happen. But there is probably a better way of doing this and that is why I was asking about it here.
Its the filename in the title? "Filename.ext - Notepad2" Whats wrong with it? it works..(as surely Path_ is your original "copied" path), but why would you do that?




