Hi all,
I'm fairly new to AHK but I am mesmerised by the immense power it has given me.
I do a lot of work on PDFs from renaming them to removing their security features via third party software.
I wish to develop an AHK script that does this:
1- opens a generic window via a shortcut key
2- I drag and drop a PDF into that window
3- AKH Script grabs the file name of that dropped PDF
4- AKH Script open another program and inserts the PDF file name into that program (I believe this can be achieved visa keyboard shortcuts/mouse coordinates)
Any help is highly appreciated.
Executer
- Micromegas
- Posts: 260
- Joined: 28 Apr 2015, 23:02
- Location: Germany
Re: Executer
Not sure if there's a way to drag and drop files, but at least you can use the following:
Code: Select all
FileSelectFile ... ; instead of steps 1-3
Run ; or
RunWait ... ; for step 4
Re: Executer
https://www.autohotkey.com/docs/command ... iDropFiles
Basically, if you have a GUI in your script, you can create a label GuiDropFiles: which will be run whenever a file is dropped on the GUI, the variable A_GuiEvent contains the name(s) of the file(s) dropped onto the GUI.
Basically, if you have a GUI in your script, you can create a label GuiDropFiles: which will be run whenever a file is dropped on the GUI, the variable A_GuiEvent contains the name(s) of the file(s) dropped onto the GUI.
Re: Executer
Example that opens any dropped *.ahk and *.txt files in notepad.exe:
Code: Select all
#NoEnv
#SingleInstance, Force
Program := "notepad.exe"
Gui, +AlwaysOnTop
Gui, Add, Text, w300, drop files below for: %Program%
Gui, Add, Edit, wp r5 vDropFiles ReadOnly
; hotkey = Ctrl+F12
^F12:: Gui, Show,, Generic Window
GuiClose:
ExitApp
GuiEscape:
GuiControl,, DropFiles
Gui, Hide
Return
GuiDropFiles:
GuiControl,, DropFiles, %A_GuiEvent%
Loop, Parse, A_GuiEvent, `n
If SubStr(A_LoopField, -3) = ".ahk"
Or SubStr(A_LoopField, -3) = ".txt"
Run, "%Program%" "%A_LoopField%"
Return
Re: Executer
Thanks Micromegas,
I'd come across FileSelectFile however using that partly defeats the purpose of my script.
I have a rather complex folder hierarchy model which requires a lot of clicking to get where I want, therefore it'd paramount that I can drag and drop the file which is already selected in a file explorer.
I'd come across FileSelectFile however using that partly defeats the purpose of my script.
I have a rather complex folder hierarchy model which requires a lot of clicking to get where I want, therefore it'd paramount that I can drag and drop the file which is already selected in a file explorer.
- Micromegas
- Posts: 260
- Joined: 28 Apr 2015, 23:02
- Location: Germany
Re: Executer
You're welcome! I just didn't know where you were at; for all I knew you might have not known about Run, but now I understand where your problem was, and I'm glad you could be helped. I'm learning from the replies, too.
Re: Executer
Here's my code so far:
The problem is CTRL+O (Send !o) is not functioning. I have tried to put a Sleep in between , that doesn't seem to work.
Any solution is appreciated.
Code: Select all
#NoEnv
#SingleInstance, Force
Program := "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PDF Password Remover\PDF Password Remover.lnk"
Gui, Add, Text, w300, drop files below for: PDF Password Remover
Gui, Add, Edit, wp r5 vDropFiles ReadOnly
; hotkey = Ctrl+F12
^F12:: Gui, Show,, Auto PDF Password Remover
GuiClose:
ExitApp
GuiEscape:
GuiControl,, DropFiles
Gui, Hide
Return
GuiDropFiles:
GuiControl,, DropFiles, %A_GuiEvent%
Loop, Parse, A_GuiEvent, `n
If SubStr(A_LoopField, -3) = ".pdf"
{
; access to loop filed var is via "%A_LoopField%"
Run, "%Program%"
; this is where I intend to do all the work with the newly opened application.
Send !o
}
else
MsgBox "Only secured PDFs can be opened"
Return
Any solution is appreciated.
Re: Executer
Try ^o for Ctrl+O.nicrox wrote:The problem is CTRL+O (Send !o) is not functioning.
!o means Alt+O.
Re: Executer
I actually found a better solution as below:
I can't however figure out how to get my file name. QPDF requires an output file name which I would like to copy and concatenate with some string.
Any help finding what is stored in %1% is appreciated.
I can't however figure out how to get my file name. QPDF requires an output file name which I would like to copy and concatenate with some string.
Any help finding what is stored in %1% is appreciated.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; TESTER
command := "D:\Program Files (x86)\qpdf\qpdf.exe --decrypt ""%1"" ""%1"""
CM_AddMenuItem( "pdf", "Remove Encryption", command )
msgbox Item added.`nRight click your file to see the new command.`nPress OK to delete.
CM_DelMenuItem( "ahk", "Test 1 2 3 " )
;msgbox Item deleted
; END OF TESTER
Return
CM_AddMenuItem( ext, label, command ) {
If( ext = "" or label = "" or command = "" )
Return false
CleanLabel := RegExReplace( label, "\W", "" )
RegRead FileType, HKCR, .%ext%
If( Not FileType )
Return false
RegWrite REG_SZ, HKCR, %FileType%\shell\%CleanLabel%,, %label%
RegWrite REG_SZ, HKCR, %FileType%\shell\%CleanLabel%\command,, %command%
Return true
}
CM_DelMenuItem( ext, label ) {
If( ext = "" or label = "" )
Return false
CleanLabel := RegExReplace( label, "\W", "" )
RegRead FileType, HKCR, .%ext%
If( Not FileType )
Return false
RegDelete HKCR, %FileType%\shell\%CleanLabel%
Return true
}
Re: Executer
If you mean something like "example.pdf" -> "example_decrypted.pdf" or whatever, something like this should work:In batch parameters (essentially what you're dealing with here), %~n1 is the filename and %~x1 is the extension.
if you simply want to prefix the filename, it's even simpler like ""decrypted_%1""
EDIT: For a full reference about this:
Code: Select all
command := "D:\Program Files (x86)\qpdf\qpdf.exe --decrypt ""%1"" ""%~n1_decrypted.%~x1"""
if you simply want to prefix the filename, it's even simpler like ""decrypted_%1""
EDIT: For a full reference about this:
Code: Select all
%* in a batch script refers to all the arguments (e.g. %1 %2 %3
%4 %5 ...)
Substitution of batch parameters (%n) has been enhanced. You can
now use the following optional syntax:
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
Re: Executer
Thanks SifJar
I tried using your solution.
the command works properly however the naming appears as: %~n1_decrypted.%~x1
I tried to remove quotes but the results are the same
I tried using your solution.
the command works properly however the naming appears as: %~n1_decrypted.%~x1
I tried to remove quotes but the results are the same
Re: Executer
Hmm, it appears I may have been mistaken, it may not be possible to use those modifiers via the registry. In which case I can't think of anyway to do it directly, but you could have another AHK script which simply takes an argument, modifies the name and then runs the program, something like this:
Then your command to be added to the registry would become script.ahk %1 where script.ahk is your "wrapper" script
Code: Select all
path = %1% ; first argument
SplitPath, path,,dir,ext,name
output := dir . "\" . name . "_decrypted." ext
Run, D:\Program Files (x86)\qpdf\qpdf.exe --decrypt %path% %output%
Re: Executer
I found a way to get around this issue.
I had to change PDF library.
command := "C:\Program Files (x86)\PDF Password Remover v3.1\pdfdecrypt.exe -i ""%1"""
Now my script works perfectly.
I had to change PDF library.
command := "C:\Program Files (x86)\PDF Password Remover v3.1\pdfdecrypt.exe -i ""%1"""
Now my script works perfectly.
Who is online
Users browsing this forum: Jacquesyip and 122 guests