3

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)

  • Hi, I think I figured it out, I added the following code and it works: tell application "Finder" to activate - new line - tell application "Finder" to reveal the last file – Zuzie May 15 '18 at 12:32
  • ...but if there are easier ways to do any of this or cleaner code, please advise... I want to learn more about coding, it's fun :) Thank you! – Zuzie May 15 '18 at 12:39
1

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!

0

Your solution

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

does not reveal the screen shot file, on my system which is running the latest version of macOS High Sierra,

However,this code does reveal the proper file for me...

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"
set hmmm to do shell script "screencapture -R1079,113,773,1033 -tpng" & space & quoted form of thePath

tell application "Finder"
    activate
    reveal thePath as POSIX file
end tell
  • Good for you :) – Zuzie May 17 '18 at 10:11
  • My sys is macOS Sierra Version 10.12.6 I tryed the lines you did, before settling for the two liner, but I think I only wrote reveal thePath in line 3 and it didn't work for me. I am a newbie to coding :) Why is there 'as alias' at the end? – Zuzie May 17 '18 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .