AutoHotkey Community

It is currently May 26th, 2012, 9:25 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: August 3rd, 2009, 4:17 pm 
Offline

Joined: April 17th, 2007, 7:36 pm
Posts: 22
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 4:55 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 6:52 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 7:05 pm 
Offline

Joined: April 17th, 2007, 7:36 pm
Posts: 22
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 7:11 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 7:14 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
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+.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 10:36 pm 
Offline

Joined: April 17th, 2007, 7:36 pm
Posts: 22
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 :) 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 10:39 pm 
Offline

Joined: April 4th, 2008, 8:15 pm
Posts: 538
Location: Canada
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 10:50 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
take the "/" out, so its like this:
Code:
RunWait, "C:\Program Files\s3copy\s3copy.exe" "%dir%\%name_no_ext%\" bucket "%title%.zip" amazonAccessCode amazonSecretKey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 11:53 pm 
Offline

Joined: April 17th, 2007, 7:36 pm
Posts: 22
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 12:10 am 
Offline

Joined: April 4th, 2008, 8:15 pm
Posts: 538
Location: Canada
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 August 4th, 2009, 2:12 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 12:27 am 
Offline

Joined: April 17th, 2007, 7:36 pm
Posts: 22
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, wolverineks and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group