-
Editing PDF file by pdftk
“pdftk” is a command line tool which have a rich functions to edit PDF file. The command line tool can edit pdf files even you do not launch a heavy application. In addition, the command line tool can be used in scripts, batch files. This enables you to edit PDFs ...
-
Automate GUI Control [PowerShell]
2017/12/14 GUI, PowerShell
PowerShell script can simulate keyboard stroke. This behavior can automate applications which do not support command line. At this time, I made a script which run Notepad, input text and save it as a file. Code
12345678910111213141516171819202122232425262728#Press Windows key[System.Windows.Forms.SendKeys]::SendWait("^{ESC}")#Input "run"[System.Windows.Forms.SendKeys]::SendWait("run")Start-Sleep -s 1#Press Enter key[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")Start-Sleep -s 1#Input "notepad"[System.Windows.Forms.SendKeys]::SendWait("notepad")[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")Start-Sleep -s 1#Input "This is a test script"[System.Windows.Forms.SendKeys]::SendWait("This is a test script.")#Press Control+S key[System.Windows.Forms.SendKeys]::SendWait("^s")Start-Sleep -s 1[System.Windows.Forms.SendKeys]::SendWait("newtext.txt")[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")Start-Sleep -s 1#Press Alt+F4 key[System.Windows.Forms.SendKeys]::SendWait("%{F4}")Explanation This script just press keys by SendKeys. The following page is the ...
-
Make an image downloader [PowerShell]
2017/12/14 PowerShell
PowerShell - a tool bundled on Windows has rich functions to extract elements in HTML pages easily. I made a script to download images in a HTML page. Code
12345678910111213141516171819202122Param( $url )#Get the web page from the URL in the argument$page = Invoke-WebRequest $url#Download imagesforeach($linkElement in $page.Links.href) {# Set the file name as the last string of the path$fileName = Split-Path $linkElement -Leaf# Get extension from the file name$extension = [IO.Path]::GetExtension($filename)# In case of the extension is ".jpg" or ".png"if ( $extension -eq ".jpg" -or $extension -eq ".png") {# Get the file of the link and save itInvoke-WebRequest $linkElement -OutFile $fileName}}Get arguments on PowerShell script In order to get arguments on PowerShell, "Param(arg1, arg2, ...)" is used. At this time, ...