AutoHotkey Community

It is currently May 27th, 2012, 11:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: September 1st, 2010, 4:51 am 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
I need to make a script that opens the most recent .jpg file in a directory. Any help greatly appreciated.
Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 9:25 am 
Loop (files & folders)

Good luck. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 9:27 am 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
thanks, but can you please elaborate?

I need to run a script triggered by a key press which shows the most recent .jpg file. Can you put Loop into context please?
thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 10:04 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
This opens the most recent .jpg in the scripts folder
Code:
Loop, %A_ScriptDir%\*.jpg
{
If (A_LoopFileTimeCreated>Rec)
  {
  FPath=%A_LoopFileFullPath%
  Rec=%A_LoopFileTimeCreated%
  }
}
Run %Fpath%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 10:18 pm 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
Aha! Great thanks! To take it one step further, is there a way to "monitor the folder for new files" and have it trigger once a new file is detected? That would be the icing on the cake.

Thanks alot!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 10:36 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
There is a FieSystemWatcher class. Not sure how to impliment it into AHK though.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 10:56 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Code:
Folder=C:\Files\MoreFiles
Loop, %Folder%\*.* ;preset list so sound does not play on startup
 ListOld.=A_LoopFileName
Loop {
List=
Loop, %Folder%\*.*
 List.=A_LoopFileName
If (List<>ListOld)
 SoundBeep ;play a sound when the files have changed
ListOld:=List
Sleep 10000
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 11:58 pm 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
thanks alot... but can't get it to work. i placed a new image in the folder and no beep. any ideas?
thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2010, 12:10 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
jjjames wrote:
any ideas?

Is your Pc Speaker (the one inside the case) turned off? Try just soundbeep in a script
Did you change the Folder Var at the top to reflect the Folder you want? if you want the folder that the script is in look at the differences between the first one and this one :)
Is it there anything else in the script you are trying it in that might interfere?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2010, 1:51 am 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
My laptop doesn't beep :D I put in a dialog box and it works good!

So now, is there anyway for the script to determine WHICH file was added and then open that file?

Cuz right now an event fires when there is a new file added, but it doesn't interact with said file.

So if beach.jpg gets added, can the script open beach.jpg once it detects a new file?

Thanks alot!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2010, 7:02 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Just Combine the two :)
Code:
Loop, %A_ScriptDir%\*.jpg
 ListOld.=A_LoopFileName
Loop {
List=
Loop, %A_ScriptDir%\*.jpg
{
 List.=A_LoopFileName
If (A_LoopFileTimeCreated>Rec)
  {
  FPath=%A_LoopFileFullPath%
  Rec=%A_LoopFileTimeCreated%
  }
}
If (StrLen(List)>StrLen(ListOld)) ;checking length so it only opens if file added not deleted
 Run %Fpath%
ListOld:=List
Sleep 1000
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2010, 2:37 am 
Offline

Joined: August 9th, 2009, 9:27 am
Posts: 35
Aha! Works great! Thank you very much :)


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, MSN [Bot], Yahoo [Bot] and 16 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