Driving me Loopy

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
burton2
Posts: 21
Joined: 18 Sep 2017, 10:20

Driving me Loopy

18 Sep 2017, 11:12

I apologise in advance for my uselessness. Im not very good at this but somehow I manage to bodge things together, mainly by using other peoples work. But this time im stuck.

What im trying to do... I want to be able to start a script that will open a png with photoshop. But I dont want to open another png with a similar name.

Example:
C:/Backgrounds/Blue/ blue-screen.png
C:/Backgrounds/Blue/ blue-screen-02.png
C:/Backgrounds/Blue/ blue-screen.txt
C:/Backgrounds/Red/ red-screen.png
C:/Backgrounds/Red/ red-screen-02.png
C:/Backgrounds/Red/ red-screen.txt

So I want to open just blue-screen.png with photoshop while ignoring screen-02.png. I dont want to edit each script with full path to png's. I want to be able to drop a script in each folder, create a shortcut and use that to open "blue/blue-screen.png" with photoshop.

Code: Select all


Loop, %A_ScriptDir%\*.*, 0, 0
{
	If (A_LoopFileExt = "png") 
	{
		LoopFileName = %A_LoopFileName%	
		LoopFileName := (LoopFileName, "\.png")
		if(a_loopfileName!="A_LoopFileName-02.png")
		run, "photoshop.exe" %A_LoopFileLongPath%
	}
}
This is what iv got. But it opens all png's within working directory with photoshop. I cant figure out how to ignore the -02.png. Normally I manage to muddle through but iv been at it to long. Please help.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Driving me Loopy

18 Sep 2017, 11:24

if(a_loopfileName!="A_LoopFileName-02.png")
This isn't making sense to me. None of your files are going to have the string name A_LoopFileName-02.png -- your examples were red-screen-02.png and blue-screen-02.png. I'm not sure if you were trying to use the LoopFileName custom variable, but that is not used in your If statement, and I'm not sure how you would even use it.

What I think instead you would like is something such as If !RegExMatch(A_LoopFileName,"-02\.png"). The ! serving as a logical-not operator, and RegExMatch() searches for the string -02.png -- if it is not found, RegExMatch returns 0, and If !0 is true. (Instead of RegExMatch() you could use IfInString().)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Driving me Loopy

18 Sep 2017, 19:04

Code: Select all

file := ""
Loop,% A_ScriptDir "\*.png", 0, 0
{
	array := StrSplit(A_LoopFilename,"-")
    file := (array[2] != "screen.png") ? Continue : A_LoopFileName
    MsgBox % "photoshop.exe " . file
    }
Not tested (while being on iOS).
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Driving me Loopy

18 Sep 2017, 20:07

That shouldn't work like you hoped BoBo, as this uses a custom variable "Continue" and not the command Continue. You'd just get a MsgBox that says photoshop.exe, because Continue the variable has no value, so file has no value.

This should work instead:

Code: Select all

If (array[2] = "screen.png")
MsgBox % "photoshop.exe " . file
A little explanation for burton2: If the second element in the array is screen.png, then you want to open it in photoshop. If the name is red-screen-02.png then the second element per that StrSplit() is "screen" and the third is "02.png", as compared to red-screen.png resulting in the second element being "screen.png" and there being no third element.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Driving me Loopy

18 Sep 2017, 22:19

Exaskryz wrote:That shouldn't work like you hoped BoBo, as this uses a custom variable "Continue" and not the command Continue. You'd just get a MsgBox that says photoshop.exe, because Continue the variable has no value, so file has no value.
[...]
Oops, wasn't aware of that! For unknown reason I thought that a command would take precedence over a variable :? :silent:
Thx for the correction and your explanations :thumbup: much appreciated!

PS. Hell, the code box is obviously smarter than me, it coloured 'Continue' correctly as a variable :oops:
burton2
Posts: 21
Joined: 18 Sep 2017, 10:20

Re: Driving me Loopy

20 Sep 2017, 15:27

That didnt work. Im sure the script is working but it crashes photoshop. Crashes vlc if I change it for mp4 as well. "Bulk rename utility" doesn't crash but no file opens with it.

I got frustrated and went for fileselectfile with a hotkey instead. Im not sure if there is a bug with fileselectfile but with this

Code: Select all

FileSelectFile, filename, , C:\Background, , (*.jpg; *.png;)
If I run it from the .ahk then it works fine but if I ran it from a .exe then the starting directory would change to a subfolder of C:\Background after the first png had been selected. Googled it and found someone else had the same problem so used his/her work around.

Anyway I just wanted to thank you guys for helping.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: william_ahk and 57 guests