Screenshot command not working

I'm trying to set up a simple screenshot of a selected area. I want the file to be named with the date and time and saved to the clipboard as a jpg. When I run the action I get a screenshot but it doesn't name it and its saved as .tiff. Where am I going wrong with this?

myTime=`date +%Y-%m-%d_%H%M%S`;screencapture -s -tjpg -c

You're capturing directly to the clipboard (the -c flag) rather than to a file -- are you creating the file in another macro step? If so, that's where the naming problem is. And you need a space between -t and jpg to set the format.

You're collecting a time stamp in $myTime, but never actually using it. If you want screencapture to write directly to a file with that name then the command would be more like:

myTime=$(date +%Y-%m-%d_%H%M%S);screencapture -s -t jpg ~/Desktop/${myTime}.jpg

...changing the path to the file to suit your needs.

Actually I am trying to capture the screenshot to the clipboard with the name is that possible?

Perhaps start from scratch and describe what you are trying to achieve, and why -- if you want "image and time stamp on clipboard so they can be pasted into a document" it would be much easier to use named clipboards and catch the stamp to one, the image to the other, then paste them separately.

(AFAIK, a clipboard takes a "thing". That "thing" might have multiple presentations, depending on what you then do with it -- Copy a file in the Finder and it'll present as both "text" and "item" -- but it's still one "thing". You're trying to put two "things" on there, which suggests two clipboards or some other workaround.)

It's pretty simple. I often need a to capture a screenshot of what I'm working on and paste it in an email or pdf or chat box. But I would like to control the name and file type. So at it's basic level I could just use a screenshot as a jpg that is in the clipboard. Right now if I just run the shell script, screencapture -s -t jpg I get a PastedGraphic.tiff. So first I'm wondering, shouldn't that command do that basic functionality. The end goal is to have that screenshot timestamped and as a jpg on my clipboard ready to go. BTW, thanks for your time, and I will use your suggestion above on another macro I have in mind.

Try, in Terminal, running:

screencapture -s -t jpg -c

...then dragging out your capture area. The switch to finder and from the "Edit" menu select "Show Clipboard". You'll see that you have your image in JPEG form. But it has no name, and there's no facility to add one, because the Clipboard holds one thing and that thing is the image you just copied there.

You might be able to get round this in KM by using a "Named Clipboard" and setting the name of the clipboard you use to the timestamp -- I don't know, I haven't played with Named Clipboards yet, and you may not be able to change the name programmatically.

A file has a name, not something on the Clipboard. An image in a PDF doesn't have a name, it's just a collection of pixels/lines, so any timestamp would have to be added separately. For email, that's Mail translating what you pasted in to a mail attachment -- it converts it to a tiff even though you gave it a JPEG, and gave it a default name because files have to have names.

So, from what you've described, it sounds like what you really need to do is automate the saving of the screenshot to a named file on disk then the insertion of that file into the program of your choice. Saving the screenshot to a file named with the timestamp is the command I gave you above, how you do the next step will very much depend on the program you are aiming at.

You nailed it, I had no idea this is how it worked.I will explore this idea, thank you very much.