Support Center » Knowledgebase » EyeTV 3: AppleScript samples: Triggered Scripts
 EyeTV 3: AppleScript samples: Triggered Scripts
Solution
EyeTV 3 introduced a new feature called Triggered Scripts. This feature allows an AppleScript to be run automatically when a particular event, or trigger occurs. Currently, the six triggers in EyeTV 3 are:

ScheduleCreated - triggers a script when a schedule is created.

RecordingStarted - triggers a script when a recording starts.

RecordingDone - triggers a script when a recording finishes or stops.

ExportDone - triggers a script when an export finishes or stops.

RecordingDeleted - triggers a script when a recording is deleted.

CompactingDone - triggers a script when a recording is compacted.

Below are some sample AppleScripts for each trigger (work in progress). To make a triggered script from these samples:

1) Copy the script text to a new Script Editor application window
2) Compile the script
3) Save the script with the appropriate name ([name of trigger].scpt)

Place these scripts within this folder:

HD/Library/Application Support/EyeTV/Scripts/TriggeredScripts

You may need to create this folder if you have never used triggered scripts before.



You must quit and relaunch EyeTV for it to be aware of new scripts:



Basic Script Packs



Sleep Scripts Pack



This includes compiled AppleScripts to sleep your Mac via EyeTV, using the RecordingDone and ExportDone triggers. The code for these scripts is included below.


-- RecordingDone.scpt
-- Sleep:This script sleeps your mac after EyeTV completes a recording.
 

on RecordingDone(recordingID)

        tell application "System Events" to sleep

end RecordingDone



-- ExportDone.scpt
-- Sleep:This script sleeps your mac after EyeTV completes an export.


on ExportDone(recordingID)

        tell application "System Events" to sleep

end ExportDone



Download Sleep Scripts Pack - SleepScriptsPack.zip (4K)

Most likely, you will just want to install one of these scripts, but not both.

Place these scripts within the folder:

HD/Library/Application Support/EyeTV/Scripts/TriggeredScripts

You may need to create this folder if you have never used triggered scripts before.
You must quit and relaunch EyeTV for it to be aware of new scripts.





Shut Down Scripts Pack



This includes compiled AppleScripts to shut down your Mac via EyeTV, using the RecordingDone and ExportDone triggers.
The code for these scripts is included below.


-- RecordingDone.scpt
-- Shut Down: This script shuts down your mac after EyeTV completes a recording.


on RecordingDone(recordingID)

        tell application "System Events" to shut down

end RecordingDone



-- ExportDone.scpt
-- Shut Down: This script shuts down your mac after EyeTV completes an export.  

on ExportDone(recordingID)

        tell application "System Events" to shut down

end ExportDone



Download Shut Down Scripts Pack - ShutDownScriptsPack.zip (4K)

Most likely, you will just want to install one of these scripts, but not both.

Place these scripts within the folder:

HD/Library/Application Support/EyeTV/Scripts/TriggeredScripts

You may need to create this folder if you have never used triggered scripts before.
You must quit and relaunch EyeTV for it to be aware of new scripts.



For ScheduleCreated:



-- ScheduleCreated.scpt
-- Free Space Check: This script checks the available disk space on the drive containing the "EyeTV Archive" and compares that to the approximate size of the scheduled recording that you have just made. If you would end up with less than 2 GB of free space afterwards, it will raise a dialog box to warn you.

on ScheduleCreated(programID)

        tell application "EyeTV"

                get the name of program id programID

                set mydur to (get the duration of program id programID) / 3600

 --MyQual is the approximate GB/hour of your current recording quality. Adjust this value as necessary. For standard resolution recordings, this will be about 1.8 - 2.7. For 720p recordings, it is about 6. For 1080i, about 8.

                set myqual to 2

                set mysize to mydur * myqual

                set AppleScript's text item delimiters to {":"}

                set mydrive to (text items 1 thru 1 of (get the repository url as string)) as alias

        end tell

        tell application "Finder"

                set myspace to (get free space of disk mydrive) / (1024 * 1024 * 1024)

                if mysize > (myspace - 2) then

                        display dialog "This schedule will take approximately " & mysize & "GB of space. This may cause your EyeTV Archive drive to run out of space." buttons {"Ok"}

                end if

        end tell

end ScheduleCreated






For RecordingDone:

 

-- RecordingDone.scpt
-- Shut Down:This script shuts down your mac after EyeTV completes a recording. At the completion of a recording, this script will raise a dialog box stating that it will shut down your Mac in 3 minutes unless the dialog box is dismissed.

on RecordingDone(recordingID)

        set myapp to "EyeTV"

        tell application myapp to quit

        delay 10

        with timeout of 300 seconds

                display dialog "This mac will shut down in 3 minutes unless you click Stop!" with icon 0 buttons {"Stop!"} giving up after 180 default button "Stop!"

                set theresults to the result

                if gave up of theresults is true then

                        tell application "System Events" to shut down

                end if

        end timeout

end RecordingDone




-- RecordingDone.scpt
-- Selective Rename: This script will selectively rename a finished recording so that the name consists of the date, followed by "myshortname". So if you were recording "Sesame Street", you could replace myshortname with "Ernie", and the script would rename the recordings to "YYYY-MM-DD-Ernie

on RecordingDone(recordingID)

        tell application "EyeTV"

                set newrecording to (recordingID as integer)

                set isshow to get the title of recording id newrecording

 --mysearch should be specified to the particular show you are selectively renaming.

                set mysearch to "happy"

                if isshow contains mysearch then

 --replace "myshortname" with the short name of your choice.

                        set the title of recording id newrecording to ((year of (current date) as number) & "-" & (month of (current date) as number) & "-" & (day of (current date) as number) & "-" & "myshortname" as text)

                end if

        end tell

end RecordingDone






For ExportDone:



-- ExportDone.scpt
-- Delete Original After Export With File Duration Check: This script attempts to compare the original EyeTV recording duration to the exported file's duration of the same name. If they are within 1% of each other, then the script deletes the recording. Warning: This script, when enabled, will automatically delete content without a prompt.

on ExportDone(recordingID)

        set myid to recordingID as integer

        tell application "EyeTV"

                set origdur to get the actual duration of recording id myid

                set myshortname to get the name of recording id myid

        end tell

 delay 5 --if the script does not seem to work, try increasing this delay slightly.

        tell application "iTunes"

                tell playlist "TV Shows"

                        set mytv to (get the location of every track whose name is myshortname)

                        if the (count of mytv) is 1 then

                                set mylocation to item 1 of mytv as string

                        else

                                display dialog "There were multiple iTunes tracks named " & myshortname & ". No EyeTV recordings were deleted."

                        end if

                end tell

        end tell

 

        tell application "QuickTime Player 7"

                if mylocation is not {} then

                        open file mylocation

                        set exportdur to get the (duration of document myshortname) / (get the time scale of document myshortname)

                        quit

                end if

        end tell

 

        if origdur > exportdur then

                set thediff to (origdur - exportdur)

        else

                set thediff to (exportdur - origdur)

        end if

 --Small discrepancies between the original file duration and the exported file duration can occur during exports. To compensate for this, the script assumes that if the difference in file duration is less than 1% of the total duration, then the export was successful.

        if thediff < origdur * (0.01) then

 --uncomment the line below to enable file deleting.

 --tell application "EyeTV" to delete recording id myid

        end if

end ExportDone



-- ExportDone.scpt
-- Automatic sync in iTunes: This script forces iTunes to sync the recording to a connected iPod, iPhone or iPad immediately after export.

on ExportDone(recordingID)

        tell application "EyeTV"

                set theRec to recording id (recordingID as integer)

 --display dialog "ExportDone: " & (title of theRec)

        end tell

        tell application "iTunes"

                repeat with myDevice in sources

                        if (kind of myDevice is iPod) then update myDevice

                end repeat

        end tell

end ExportDone





For RecordingDeleted: (coming soon)


Article Details
Article ID: 2727
Created On: 27 Jun 2008 10:35 PM

 This answer was helpful  This answer was not helpful
 Back
 Search
Loading
 Article Options
Home | Contact Tech Support | Knowledgebase | Downloads | English | Deutsch | Français |

Help Desk Software By Kayako eSupport v3.40.01