Screenshot -> overwrite to new filename

Posted on
Tue May 21, 2019 3:25 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Screenshot -> overwrite to new filename

So I have an action with two embedded scripts... the first is in python (don't remember who or how I got it)... the 2nd half of the action is in AppleScript (need help). So... when my rotating image "R.jpg" goes 3 minutes without an update (timer expires) then this action is called that changes the "R.jpg" image into a screenshot of a control page. (Basically puts a control page inside of a control page as a refreshing image)

1) Python script to take a snapshot image of a control page and save on the desktop as "ISL-Thumb.jpg". (not sure where the "Thumb" comes from and I think I had to add webkit to python to get this to work)

Code: Select all
import subprocess as sub
try:
    p = sub.Popen(['/usr/local/Cellar/webkit2png/0.7/bin/webkit2png', '-T', 'http://10.0.6.10:8176/controlpage?name=ISLMainLS', '-D', '/Users/williammoore/Desktop', '-s', '.5', '-o', 'ISL'],stdout=sub.PIPE,stderr=sub.PIPE)
    output, errors = p.communicate()
    errorMsg = ''
    if errors != '':
        errorMsg = 'Error Detected with webkit2png : %s' % errors
    indigo.server.log('WEBKIT2PNG: %s\n%s' % (output, errorMsg))
except OSError, e:
    indigo.server.log('OSError invoking webkit2png: %s' % e)

The second half is where things go astray and the second half I use for other stuff as well.... like copying a static image from a folder and saving it as my "R.jpg" image when there isn't a better live image to capture (from a camera or webpage, etc...)
Code: Select all
property outputPNGFN : "Users:williammoore:Desktop:IPCamRotate:R.jpg"
property noMotionFN : "Users:williammoore:Desktop:ISL-thumb.png"
property targetSize : 256

on run
   my outputPlaceholderImage(noMotionFN)
end run
to outputPlaceholderImage(filename)
   set outputFileHandle to (open for access (outputPNGFN as alias) with write permission)
   try
      write (read (filename as alias)) to outputFileHandle starting at 0
      close access outputFileHandle
   on error err_msg
      close access outputFileHandle
   end try
end outputPlaceholderImage

Any help would be great.

Bill
My Plugin: My People

Posted on
Tue May 21, 2019 9:18 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Screenshot -> overwrite to new filename

That’s a long winded AppleScript!

The Python you need is:

Code: Select all
 from shutil import copyfile

copyfile(src, dst)

Where src is your thumb and dst is r.jpg.

Not at pc to type out your full version right now.


Sent from my iPhone using Tapatalk Pro

Posted on
Wed May 22, 2019 11:09 am
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: Screenshot -> overwrite to new filename

howartp wrote:
That’s a long winded AppleScript!

Yeah, I ripped it off from a script used to extract iTunes cover art as a png file and adjust the size and convert to a jpg file so it could be brought into a control page. I can't remember the last time I controlled iTunes from indigo, so not worrying about updating that script.

howartp wrote:
The Python you need is:
Code: Select all
 from shutil import copyfile

copyfile(src, dst)


Perfect. Worked like a charm. And combining those scripts into one script seems to be executing much faster. Much thanks.

Bill
My Plugin: My People

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests

cron