Ideally, I would be able to take a screenshot and paste the image directly into iA Writer. Since iA Writer doesn't store images, however, this is not possible.

In order to not have to manually drag every screenshot into iA Writer, I would like to be able to

  • take a screenshot,
  • save it in a folder
  • copy the file path to clipboard
  • paste the file path into iA Writer.

So far, I've changed the default folder for storing Screenshots and added a folder action. I found a script that copies the screenshot to my clipboard as a file. However, I can't figure out how to copy the file path to my clipboard instead, so I can easily paste it into iA Writer. Any ideas? Could there be a better way?

on adding folder items to this_folder after receiving added_items
    set the clipboard to (read (last item of added_items) as TIFF picture)
end adding folder items to
  • Try set the clipboard to the POSIX path of the last item of added_items if you want the POSIX pathname of the item, or set the clipboard to the last item of added_items as text if you want an alias type pathname. – user3439894 Mar 1 at 15:25

This should work for you

property thePath : missing value

on adding folder items to theFolder after receiving theNewItems
    set thePath to POSIX path of theNewItems

    set the clipboard to thePath -- copies the file path to clipboard
    -- set the clipboard to POSIX file thePath -- copies actual file to clipboard

end adding folder items to
| improve this answer | |
  • 1
    If theNewItems contains more than one item, then this is not going to give the desired results. Also, why did you declare thePath as a property ? It's not necessary or useful. – CJK Mar 1 at 19:41
  • He can only take one screenshot at a time. Any items that are already in that folder that were already processed, Will not be processed again. I added property thePath because without it, Script Debugger does not show the value in the results and variables tab – wch1zpink Mar 1 at 19:51
  • 1
    Screenshots can be taken in successive bursts, say, by an automated script, that can add files to a folder sufficiently fast enough such that they will be passed to the folder action as a collection. In this particular use case, as outlined by the OP, you are correct in that this is not an eventuality he needs to think about, but if we are sharing code online—or even just wishing to write code for ourselves—we should aim to publish code that's as robust as possible, not just for the OP, but for future users, especially when it can be achieved with minimal effort. – CJK Mar 1 at 19:58
  • 1
    Re: thePath: I can understand why you would want the property value to be present during your own debugging process, but these should always be removed before publishing the script online. It's confusing to anyone who doesn't know AppleScript, and isn't a functional element of the script. I believe if you have the handler return thePath, then that will allow Script Debugger to evaluate it for you as well. In Catalina, properties declared at the top-level of the script are problematic for anyone who'd use this as part of larger script asking for authorisation. – CJK Mar 1 at 20:02

You must log in to answer this question.

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