Seeking script to add to the automator service to make it reveal newly created item in finder

applescriptautomatorbashfinderterminal

After much research (I am not familiar with Shell, Bash coding… and only just discovered the magic of Automator and Terminal usefulness), I've created an Automator service that captures a shot of specific rectangle of my screen and saves it on desktop upon press of a shortcut key. It runs well, but it would be handy, if I could add code to it, that would then reveal the new image in Finder. I don't want to open the newly created image, just to reveal and highlight it in finder, so I can take several images in succession and see that they were created without having to do anything else with them at the time.

My 'Run AppleScript' in Automator at the moment:

set theDate to do shell script "date +%Y-%m-%d"
set theTime to do shell script "date +%H.%M.%S"
set theTempPath to POSIX path of (path to desktop)
set thePath to theTempPath & "screenCapture " & theDate & " at " & theTime & ".png"
do shell script "screencapture -R1079,113,773,1033 -tpng" & space & quoted form of thePath

There might be another way to do this, I am complete novice to this tweaking 🙂 I know that something can be done to the folder itself through Folder Actions Setup, but I want the folder to reveal the new item only when I've run this service, not each and every time I add something new.
Your help would be much appreciated.
Thank you! (my apologies for mistakes and typos)

Best Answer

I figured it out for myself in the end - perhaps this will be useful to others :) I added these lines to my code and they work - they reveal the newly created screen shot highlited in Finder:

tell application "Finder" to activate
tell application "Finder" to reveal the last file

I am aware there is probably a cleaner code to do all of this and if you feel like advising me on that, please do not hold back - I am keen to learn more :) Thank you!