Script fine when invoked manually, fails when unattended

Hi all

I still use EyeTV4 for recording on-air TV in the UK, but its makers Geniatech have closed down the paid subscription service for the EPG, leaving us with just on air DVB listings. Of course they made the paid service automated for updates but not the free one. So I wrote a script which updates the EPG by clicking on a refresh icon in the EPG screen.

The script works perfectly when invoked manually, either from within Script Editor or by clicking the scripted app I made. But if you let the display sleep (the Mac is set not to let the disks sleep or auto-sleep when the display is off, so the only sleeping which happens is the display goes off), then it fails, every time. I have tried calling the app from Lingon and from a calendar event, same problem. I have tried setting energy saver to wake from sleep 5 mins before the script runs, same problem. I have removed and re-added the script to Accessibility, Files & Folders and Full Disk Access in the Security & Privacy preference panel. Script Editor also has privileges in Accessibility and FDA. But always the same error…

System Events got an error: Can’t get window 1 of process “EyeTV”. Invalid index. (-1719)

i.e. it can’t access the main EyeTV window unless the process is launched manually.

My script is:

tell application "EyeTV"
	enter full screen
end tell
delay 2
tell application "System Events"
	delay 2
	tell process "EyeTV"
		keystroke "g" using command down
		delay 1
		click (button 6 of splitter group 1 of window 1)
	end tell
end tell

(Formatting backticks added by NG.)

Keystroke “g” makes sure that the EPG window of EyeTV is the open one. Button 6 etc. is the refresh button in the corner of the EPG window.

Can anyone think of anything I can do to make this run, please?

Thanks in advance for any ideas.



Hi tsp1965. Welcome to MacScripter.

I don’t know the exact answer to your problem. But I’ve noticed on one of my machines that when the screen wakes from sleep, the frontmost visible application isn’t necessarily the frontmost process. It would be a good idea to add the line set frontmost to true after tell process “EyeTV” to give the GUI scripting the greatest chance of working. No guarantees, but it’s something to try. You haven’t said if EyeTV actually opens, so I don’t know if the problem’s occurring before then.

BTW. AppleScript code can be formatted for posting on this site by copying it in as plain text with linefeed line endings and with three backticks on the line above and on the line below:

AppleScript code here

It makes the code appear in its own box with a button that people can click to open it in their own script editors. :slightly_smiling_face: I’ve done this for you in your post above. There’s more post formatting information in the “Markdown Reference” here.

Hi and thanks for the ideas.

I’ve modified the script and will post back when I have found whether it works!

I did have a different idea, which was to make a small automator app to simply click on the dock icon for the updating app. It hasn’t thrown an error on testing yet, but I’m also not 100% sure it is doing anything at all!

Thanks again.