Open Selected Image File With Chosen Image Editor

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
V0RT3X
Posts: 362
Joined: 20 May 2023, 21:59
Contact:

Open Selected Image File With Chosen Image Editor

19 Mar 2024, 10:46

I work with a lot of image manipulation and am constantly having to open images, only to close some and open others.
The usual method of [Select file > Right click > Open with > Drill down to your program] is cumbersome and time consuming.
Thus, this little script. Just select your image file and press the hotkey. The image will open in the editor you set in the script's ProgPath.
The script will notify with a message box if the selected item is not a valid image file, or report if it is actually a folder rather than a file.
I attempted to make it so that more than one image file could be selected and then opened all at once to no avail.
Perhaps someone with more AHK experience can expand on this. Otherwise works great as is for what I was attempting.

Code: Select all

ProgPath := "C:\Full\Path\To\Your\Image\Editing\Program.exe"

^F3::
    SelectedItem := GetSelectedItemPath()
    if (FileExist(SelectedItem) && !IsFolder(SelectedItem)) {
        if (IsValidImageFile(SelectedItem)) {
            Run, % ProgPath " """ SelectedItem """"
        Soundbeep, 1900, 75
        Soundbeep, 1900, 75
        } else {
        Soundbeep, 1200, 75
        Soundbeep, 1000, 150
            MsgBox, , , The selected file is NOT a valid Image File., 3
        }
    } else {
        Soundbeep, 1000, 75
        Soundbeep, 1000, 75
        MsgBox, , , The selected item is a Folder`n        ...NOT a File., 3
    }
Return

;-------------------------- 

GetSelectedItemPath() {
    Clipboard := ""
    Send, ^c
    ClipWait
    Return Clipboard
}

IsValidImageFile(FilePath) {
    ImageExtensions := ".bmp.jpg.jpeg.png.gif.tif.tiff"
    FileExt := SubStr(FilePath, InStr(FilePath, ".",, -1))
    Return InStr(ImageExtensions, FileExt)
}

IsFolder(FilePath) {
    Return (SubStr(FileExist(FilePath), 1, 1) = "D")
}
Return

One issue I've noticed is it will treat some folders as images on my system, as I use a software called FolderIco to change the look of individual folders.
Apparently the script views some of them as images, although I haven't determined why yet. And as that condition is primarily intended to catch clumsy
key presses that generally aren't an issue anyhow, I'm not sure how hard I will look into it. The Soundbeeps are just simple audible notifications that
something after the hotkey is pressed is happening, and they can be removed if found annoying.
ahk7
Posts: 591
Joined: 06 Nov 2013, 16:35

Re: Open Selected Image File With Chosen Image Editor

21 Mar 2024, 15:19

V0RT3X wrote:
19 Mar 2024, 10:46
The image will open in the editor you set in the script's ProgPath.
F4MiniMenu might be something to give a spin - select files open in defined editors (default) or select from a (filtered) menu
https://github.com/hi5/F4MiniMenu?tab=readme-ov-file#screenshots Although made for Total Commander initially it should work OK-ish with Explorer (has to be activated in settings) - AutoHotkey forum thread here, as you can huge fans here on the forum :lol:
User avatar
V0RT3X
Posts: 362
Joined: 20 May 2023, 21:59
Contact:

Re: Open Selected Image File With Chosen Image Editor

21 Mar 2024, 16:42

I'll have to give that a look this weekend. Sounds like it may be just what I was looking for.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Google [Bot] and 112 guests