AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using AHK to write a .bat file

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 3:17 pm    Post subject: Using AHK to write a .bat file Reply with quote

I'm trying to use AHK to write a dynamic bat file that will ultimately resize/rename images for me. I keep getting "Empty variable reference" errors around the area of FileAppend. What am I doing wrong?

Code:
#NoEnv 
SendMode Input 
SetWorkingDir %A_ScriptDir% 

FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.ppt; *.pptx)
if SelectedFile =
    MsgBox, The user didn't select anything.
else
    FullFileName = %SelectedFile%
    SplitPath, FullFileName, name, dir, ext, name_no_ext, drive
   
   
FileAppend,
(
@echo off
set iview=C:\Program Files\IrfanView\i_view32\i_view32.exe
set ini=C:\path\to\ini\
set tini=C:\path\to\another\ini\
set source=%dir%\%name_no_ext%\
set target=%dir%\%name_no_ext%\
set oldtype=png
set newtype=gif
for %%a in ("%source%*.%oldtype%") do (
set oldname=%%~na
call :SUB
)

:SUB
set newname=%oldname:Slide=00%
"%iview%" "%source%%oldname%.%oldtype%" /ini="%ini%" /advancedbatch /convert="%target%%newname%.%newtype%"
"%iview%" "%source%%oldname%.%oldtype%" /ini="%tini%" /advancedbatch /convert="%target%-t-%newname%.%newtype%"

), C:\%dir%\%name_no_ext%\resize.txt

_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Mon Aug 03, 2009 3:55 pm    Post subject: Reply with quote

Quote:
I'm trying to use AHK to write a dynamic bat file that will ultimately resize/rename images for me
WHY?
there is nothing a BAT-file can do, that canīt be done by pure ahk.
Back to top
horntail



Joined: 03 Aug 2009
Posts: 42
Location: UK

PostPosted: Mon Aug 03, 2009 5:52 pm    Post subject: Reply with quote

Code:

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.ppt; *.pptx)
if SelectedFile =
    MsgBox, The user didn't select anything.
else
    FullFileName = %SelectedFile%
    SplitPath, FullFileName, name, dir, ext, name_no_ext, drive
   
   
FileAppend,
(
@echo off
set iview=C:\Program Files\IrfanView\i_view32\i_view32.exe
set ini=C:\path\to\ini\
set tini=C:\path\to\another\ini\
set source=%dir%\%name_no_ext%\
set target=%dir%\%name_no_ext%\
set oldtype=png
set newtype=gif
for `%`%a in `("`%source`%*.`%oldtype`%"`) do `(
set oldname=`%`%~na
call :SUB
`)

:SUB
set newname=`%oldname:Slide=00`%
"`%iview`%" "`%source`%`%oldname`%.`%oldtype`%" /ini="`%ini`%" /advancedbatch /convert="`%target`%`%newname`%.`%newtype`%"
"`%iview`%" "`%source`%`%oldname`%.`%oldtype`%" /ini="`%tini`%" /advancedbatch /convert="`%target`%-t-`%newname`%.`%newtype`%"

), C:\%dir%\%name_no_ext%\resize.txt


that should give the output i believe you wanted.

The two "%%" sections are what is causing you to get the empty variable error as ahk is seeing the %'s as the start and end of a variable reference. This is when you use the ahk delimiter "`" to tell ahk to treat them as literal %'s and not code. The "(" and ")" occurences also have to be delimited, else they could cause the fileappend to error and/or finish prematurely
Back to top
View user's profile Send private message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 6:05 pm    Post subject: Reply with quote

Thanks, horntail.

Z_Gecko. I suppose I'm just showing my ignorance as to the power of AHK. The reason I was thinking it would be better to stack a series of dynamic batch scripts is because one bat won't start running until the other has completed.

The only way I know how to delay this occurrence in AHK is by using the Sleep function and I don't always know how much time it will take. Care to shed some light on a different way of doing things for me?
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Mon Aug 03, 2009 6:11 pm    Post subject: Reply with quote

Quote:
The reason I was thinking it would be better to stack a series of dynamic batch scripts is because one bat won't start running until the other has completed.

The only way I know how to delay this occurrence in AHK is by using the Sleep function and I don't always know how much time it will take.

iīm not shure what you actually mean by that, but
maybe you just have not discovered RunWait yet.
Back to top
Murp|e



Joined: 12 Jan 2007
Posts: 474
Location: Norway

PostPosted: Mon Aug 03, 2009 6:14 pm    Post subject: Reply with quote

stuboo: I think all you need is runwait. You should also search for GDI+ as tic has created some nice scripts which can do all sorts of things with image so you won't even need IrfanView. IrfanView is good and simple, but if you'd like to do as much as possible in "pure" AHK, look into GDI+.
Back to top
View user's profile Send private message Visit poster's website
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 9:36 pm    Post subject: Reply with quote

Thanks, guys. You're right. RunWait is what I wanted to do, and I had actually seen/used it before but never really understood what the difference is between Run & RunWait.

Now that I have your attention Smile could you tell me what I might be doing wrong here?

Code:
title = This is my title
StringReplace, title, title, %A_SPACE%, -, All

RunWait, "C:\Program Files\s3copy\s3copy.exe" "%dir%\%name_no_ext%\/" bucket "%title%.zip" amazonAccessCode amazonSecretKey


I'm using s3copy to upload a zip file to amazons simple storage service, but it doesn't seem to work when I use a variable for the filename instead of a static file name.
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
PurloinedHeart



Joined: 04 Apr 2008
Posts: 374
Location: Canada

PostPosted: Mon Aug 03, 2009 9:39 pm    Post subject: Reply with quote

Code:
title = This is my title
StringReplace, title, title, %A_SPACE%, -, All

RunWait, "C:\Program Files\s3copy\s3copy.exe" "%dir%\%name_no_ext%\/" bucket "%title%.zip" amazonAccessCode amazonSecretKey



Is that / supposed to be there? Just quickly skimmed through code
Back to top
View user's profile Send private message
horntail



Joined: 03 Aug 2009
Posts: 42
Location: UK

PostPosted: Mon Aug 03, 2009 9:50 pm    Post subject: Reply with quote

take the "/" out, so its like this:
Code:
RunWait, "C:\Program Files\s3copy\s3copy.exe" "%dir%\%name_no_ext%\" bucket "%title%.zip" amazonAccessCode amazonSecretKey
Back to top
View user's profile Send private message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 10:53 pm    Post subject: Reply with quote

Removed the / but it didn't fix the problem. Is there a way to stop the cmd window from closing so I can see the output?
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
PurloinedHeart



Joined: 04 Apr 2008
Posts: 374
Location: Canada

PostPosted: Mon Aug 03, 2009 11:10 pm    Post subject: Reply with quote

Code:

FileAppend,
(
"C:\Program Files\s3copy\s3copy.exe" "%dir%\%name_no_ext%\/" bucket "%title%.zip" amazonAccessCode amazonSecretKey
pause
), Error.bat
run Error.bat


Last edited by PurloinedHeart on Tue Aug 04, 2009 1:12 am; edited 1 time in total
Back to top
View user's profile Send private message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 11:27 pm    Post subject: Reply with quote

Worked perfectly, PurloinedHeart. Thanks to everyone for the help. This community makes a great language even better.
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group