Eye TV AppleScript help

Good morning all.
I recently purchased Eye TV to record digital Freeview television while I am out of the house (UK TV). I have been toying around with AppleScript to shut down my mac after a recording has exported to iTunes for either Apple TV or my iPhone.
I have a few issues and would really appreciate some help.
1 - I am using the following AppleScript to shut down my MacBook Pro following an automatic export. The script is designed to check if Eye TV is still recording and if so ignore the shut down process, if there is no recording then a warning message will appear and if the user doesn't stop the process, the MacBook Pro will shut down after a given time period.
Here is the script :
on ExportDone(recordingID)
set isCurrentlyRecording to checkeyetv_isrecording()
if isCurrentlyRecording is false then
with timeout of 300 seconds
tell me to activate
display dialog "Warning: Export to iTunes complete. Your system will automatically shut down in 2 minutes unless you click Stop" with icon 0 buttons {"Stop"} giving up after 120 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
else
quit
end if
end ExportDone
to checkeyetv_isrecording()
delay 10
tell application "EyeTV"
if is_recording then
return true
else
return false
end if
end tell
end checkeyetv_isrecording
The first issue is this, if two programs are scheduled, (with both set to export) if the second program finishes before the first export is complete then the second will stay 'pending' until the first is finished. However the problem is, when the first program has exported this will start the AppleScript and the MacBook Pro will shut down unless manually stopped, causing the second export to crash.
Obviously the script is designed to check for a current recording, is there an additional line that could be added to check for a second export also ? Maybe a simple delay on the original export would give enough time for the second to start ? At the moment I am having no luck getting this to work.
2 - Over night I had a program scheduled to record and export followed by a shut down (no clash over a second scheduled program). When I woke in the morning the process had completed, however all three of my external HD's were active and awake, and had been all night. It seemed that these had not unmounted automatically on shutdown. Therefore I found the following script which will unmount my drives :
tell application "Finder"
set bootDisk to name of startup disk
set otherDisks to every disk whose (name is not bootDisk) and (name is not "Media")
repeat with myDisk in otherDisks
try
eject myDisk
end try
end repeat
end tell
This script ejects my drives and on shutdown they sleep until the Mac is started again. I would like to integrate this into the previous script, so the drives unmount just before the shut down is initiated. I'm just not sure where it should sit in the process, so if someone could help me with that, that would be great.
I'm very new to AppleScript and cannot confess to writing these myself, I have been lucky enough to find them online, I just need some help getting them finalised.
Any help would be greatly appreciated.
- Neil

This will do what you want. I've tried to use variable names that are explanatory, but if you have questions please ask.
Make sure you have a backup of your iTunes library and storage before proceeding. This does, after all, delete files (but they can still be found in the trash until you empty it).
Note that there is no error checking here so, for example, if no tracks qualify for deletion the script will throw an error.
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;">
tell application "iTunes"
set filesToDelete to location of (file tracks whose (video kind is TV show) and (unplayed is false))
delete (tracks whose (video kind is TV show) and (unplayed is false))
end tell
tell application "Finder"
repeat with theFile in filesToDelete
delete theFile
end repeat
end tell </pre>

Similar Messages

  • New bee looking for applescript help with text edit app

    I have a huge text files (20+) , I want to find a list of words like weather, farmers, ploughing. I want to find these words one at a time, as my text file is 250+ Mb in size.
    I want applescript to count the how many times each word appears in the text.
    Paste that occurrence of word into an spreadsheet file in a row named after text file , and in a column named weather, farmers, ploughing.
    Please help.
    Thanks much.
    CF
    PS so far I can open the text files with applescript, that is about the extent of my ability in programing.
    Message was edited by: coldfusions onco

    For a file of that size, you would need to use some shell utilities to get decent performance. To count words, the following script breaks up the text into words, then counts the number of times the specified word is found (a dictionary file is used as an example, so the match is equivalent to 'contains'):
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set theFile to "/usr/share/dict/web2" -- a 2.5MB list of words
    set someWords to {¬
    {theWord:"weather", theCount:0}, ¬
    {theWord:"farmers", theCount:0}, ¬
    {theWord:"ploughing", theCount:0}}
    repeat with anItem in someWords
    set aWord to quoted form of theWord of anItem
    try -- break up into individual words, then search and count
    set theCount of anItem to (do shell script "tr -cs '[:alpha:]' " & quoted form of linefeed & " < " & theFile & " | grep -ic " & aWord) as integer
    end try
    end repeat
    someWords
    </pre>
    Is this related to your Automator post?

  • Applescript Help: Search for text in Safari DOM tree

    Im trying to make a script really similar what was asked here: Re: Find text in webpage and email notification applescript/automator Except instead of searching the "source code" of the page, I want the script to search the "DOM tree" for the page.
    To summarize, I am trying to make a script that loads a safari page, searches for a particular text in the DOM Tree, and if found will send me an email.
    Here is the code from the other thread I referenced:
    on idle
              set pagURL to "http://page.url.com?whatever"
              if application "Safari" is not running then
                        quit
                        return
              end if
              tell application "Safari"
                        set URL of document 1 of window 1 to "http://your.web.address/"
                        delay 5
      -- delay to let page load.
                        if source of document 1 of window 1 contains "search text" then
                                  my sendAMail()
                        end if
                        return 900 --fifteen minutes
              end tell
    end idle
    on sendAMail()
              tell application "Mail"
                        set theMess to make new outgoing message at end with properties {sender:"your name", subject:"some subject line", content:"The message you want to send to yourself", visible:true}
                        tell theMess
                                   make new to recipient at end of to recipients with properties {address:"[email protected]"}
                        end tell
      -- send theMess
              end tell
    end sendAMail
    Any help would be appreciated!

    For the URL you quote as an example (http://www.sislands.com/coin70/week2/NestedLoops1.htm), using text instead of source worked for me:
    if text of document 1 of window 1 contains "1  2  3  4" then
    another example:
    if text of document 1 of window 1 contains "10 12 14 16" then
    Note a double space between single digits (1  2  3  4) and a single space between double digits (10 12 14 16) is required for a match as per the table format:
    Any full line:
    if text of document 1 of window 1 contains "for (i = 1; i <= 10; i++) { // when i = 10" then
    or partial line works:
    if text of document 1 of window 1 contains "; i++) { // when i = 10" then

  • Applescript help with true or false script

    I'm in need of a applescript that will run two different scripts based on the outcome of an existing file.
    I have a folder called Status. Inside this folder is a simple text file called Good.rtf
    I would like a script that would run one or the other script base on the true or false output.  If file exists then:
    true will
    run script A
    false will
    run script B
    I have been searching the web for two days looking for something to help me get started on this and have not had much success.
    Please help me.   I really would appropriate any help or guidance. 
    Thanks....
    Ron

    Ron
    AppleScript calls this kind of script a "Conditional" = if this > then that
    Some templates are in MacintoshHD/Library/Scripts/Script Editor Scripts/Conditionals
    You don't need a value for "false" in binary as it is merely "not true" (else)
    if true then
        -- insert if actions here
    else
        -- insert else actions here
    end if
    If you already have your Scripts A & B working, copy>pastethem into the "insert actions here" part as appropriate
    ÇÇÇ

  • AppleScript help

    Hello,
    I'm very new to using Applescript and I'm trying to get the FTP program Fetch to simply refresh every 10 seconds on a loop while keeping Fetch in the background. I have a script that works well, but once it's running I can't quit it. I have to quit Fetch first which causes the script app to open Fetch again and then brings up an error. At that point I can quit both programs. I'm sure that I'm just missing a command or two, but can't figure out what it is. I know there are some idle handler commands, but the ones that I tried didn't work. Here is what I have so far. Any help would be greatly appreciated.
    repeat
              tell application "Fetch"
      refresh file list transfer window 1
              end tell
      delay 10
    end repeat

    the best way to do this is to copy the following into the script editor and save it as a stay-open application:
    on idle
              if application "Fetch" is running then
                        ignoring application responses
                                  tell application "Fetch"
                                              refresh file list transfer window 1
                                  end tell
                        end ignoring 
              end if
              return 10
    end idle
    for stay-open applications, the system will call the idle handler every x seconds (where x is whatever you put as the return value of the handler; default is 1 second).  This is far more efficient than using a repeat/delay structure, and will prevent the script from being unresponsive. 
    the if block tells the script to call Fetch only if Fetch is already running.
    The ignoring block tells the script not to wait for a return value from Fetch, so that you don't get odd 'connection invalid' errors if Fetch quits while processing the command.

  • Applescript help - keystroke part does not work

    Hi guys, I'm new to Applescript and would like some assistance. I have an application called iVPN that I would like to start with some applescript code - just one problem in that it requires the admin password at startup.
    I tried the following, but once the dialogue box appears to enter the password, nothing happens. It seems to stop just before the "delay 10" line. I've also tried it with just the keystroke line, but nothing happens (no password appears in the dialogue box that pops up).
    Any help greatly appreciated, Thanks!.
    tell application "iVPN" to open
    tell application "System Events"
    delay 10
    key code 48 using {command down}
    keystroke "password here"
    key code 36
    end tell

    I had you download the wrong file.
    The new name is XTool-2.0.dmg.tgz Notice the missing src.
    I simplified the example applescript file. You need to write your applescript file as needed.
    The basic plan for you is to move the mouse to the button then click the button.
    --Move mouse to input field.
    move mouse {100, 10} 
    click mouse
    --fill in the data.
    --move mouse & click button
    move mouse {120, 10} 
    click mouse
    Robert
       First, there is the XTools scripting addition, which will give AppleScript the ability to move the mouse. 
       Dowload from:
          http://www.lestang.org/osax/XTool/
       click on:
          XTool-2.0.dmg.tgz 
       Installation :
       Drag XTool.osax from insite the image to one of the following locations (create the directory if it does not exist) :
       a : ~/Library/ScriptingAdditions/
       b : /Library/ScriptingAdditions/
       c : /System/Library/ScriptingAdditions/
       I have it in directory /System/Library/ScriptingAdditions/ 
       My other two directories do not exit: ~/Library/ScriptingAdditions/ & 
          /Library/ScriptingAdditions/
       see download file XTool ReadMe.rtf for documentation
    log "  --- Starting on " & ((current date) as string) & " --- "
    set {x, y} to position of the mouse
    display dialog "mouse at " & x & " " & y giving up after 3
    display dialog "Move mouse to where you want to find coordinates, you have five seconds." giving up after 5
    set {x, y} to position of the mouse
    beep
    display dialog "New mouse position at " & x & " " & y giving up after 5
    -- Go after time message
    move mouse {10, 10}
    delay 5
    -- click mouse
    -- center mouse
    -- find the size of the display with a unix command
    do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep 'Resolution'" -- get info
    tell the result to set {DisplayWidth, DisplayHeight} to {word 2, word 4} -- get resolution
    move mouse {DisplayWidth div 2, DisplayHeight div 2} -- center mouse
    Message was edited by: rccharles

  • Applescript help (wiping a shared drive)

    I was wondering if I could get some help with an applescript I want to aquire or create.
    Currently I have an xRaid as my file server. I would like to aquire or write a script and using Cron, unless there is a better way, to have it execute every Friday. This script is to completly wipe all of the data on the share drive.
    thank you in advance for your help,
    Robert
    G5   Mac OS X (10.4.6)  

    try this tip by *Chris CA*:
    Point iTunes prefs -Advanced - iTunes media folder location to the shared drive.
    Don't uncheck anything or delete anything from iTunes.
    In iTunes, select all the files you want to copy to the NAS.
    Then right click - Consolidate selected files.
    This copies the selected items to the location on the NAS.
    You can then delete these from the iTunes media folder (\Music\iTunes\iTunes media\Movies)
    when done, point +Tines media folder location+ back to the original location.
    if you want to play content of off the shared drive, be sure it is mounted before you launch iTunes.
    JGG

  • Applescript help - how do I autotype?

    Hi All!
    I'm a new to this and didn't find any examples on this site so I may be looking at a dead end. Please forgive my basic questions.
    Basically I am trying to log into a web site automatically. I thought I found the answer with autotype but even with the syntax matching the examples I have found, applescript see auto type as a variable. Is my syntax messed up, or is autotype not supported? If it is not supported can someone give me an example of how to log into the below website?
    Thanks!
    -Todd-
    Applescript:
    tell application "Safari"
    open location "https://login.yahoo.com/config/login_verify2?.done=http://finance.yahoo.com&.s rc=quote&.intl=us"
    delay 5
    activate
    end tell
    autotype "username"
    autotype "password"
    autotype "'return"

    Hi harc0urt and welcome to Apple Discussions!
    There's no such AppleScript command as "autotype", but you can type automatically using the invisible System Events application. It's not altogether reliable, but in this case it appears to work reasonably well:
    tell application "Safari"
    open location "https://login.yahoo.com/config/login_verify2?.done=http://finance.yahoo.com&.s rc=quote&.intl=us"
    delay 5
    activate
    tell application "System Events"
    keystroke "username"
    delay 2
    keystroke tab
    keystroke "password"
    delay 2
    keystroke return
    end tell
    end tell
    You will need to ensure that "Enable access for assistive devices" is checked in System Preferences: Universal Access".
    Couple of points: you have to move from field to field in the form. Just typing another word wouldn't have helped. Similarly, typing the string "return" would have typed just that.
    (FWIW I'd also point out that it's incredibly insecure practice to hard-code user names and passwords into scripts, but it's entirely up to you...)
    Hope this helps,
    H

  • TextEdit Applescript help counter of certain words

    I have tried to modify a script that finds and replaces text. My goal is to count the instances the script finds a word, say "love", and spit out the number of instances that the word "love" appears in the document so I can use it for another subroutine. Any help is appreciated.
    I have this as guideline but it seems it does not work.
    tell application "TextEdit"
    set myCountSign to text of document 1
    set myCount to count myCountSign
    repeat with this_word in myCountSign
    if (this_word as string) is "love" then
    set myCount to myCount + 1
    end if
    end repeat
    myCount
    end tell

    The most obvious problem with your script is the line:
    repeat with this_word in myCountSign
    This looks at myCountSign (a block of text) and iterates through it assigning each text object to this_word.
    The problem is that by default each 'text object' is each character therefore you're comparing each character in the text to the string 'love' which will never, ever match. Even if the word exists you'd be performing a character-by-character comparison.
    The simplest fix is to tell AppleScript to look at the words in the text, which is done simply by:
    repeat with this_word in (words of myCountSign)
    (note you might also need to do this for 'set myCount to count myCountSign' since this will return the character count, not the word count)
    There are other, more efficient ways (such as via text item delimiters):
    tell application "TextEdit"
      set myCountSign to text of document 1
      set wordCount to (count words of myCountSign)
      set {oldtids, my text item delimiters} to {my text item delimiters, "love"}
      log set keywordCount to (count text items of myCountSign) -1
      set my text item delimiters to oldtids
      display dialog "The document has " & wordCount & " words and " & keywordCount & " occurrences of the word 'love'"
    end tell
    The text item delimiters approach works by breaking the text into chunks at each occurrence of the delimiter (in this case, the string 'love'). Then all you have to do is count the number of chunks (minus 1) which is a lot quicker than counting all the words, especially for large documents.

  • Applescript help for Exporting Playlist

    I have two Imac...... my business mac at a resturant/bar for djing and my home Imac for purchasing and orgainizing my music collection.
    I frequently replace music audio and video files for better quality versions,
    This is causing me headaches because at work we might have a lot of smartlists which are based on ratings and other tags.  I need to get the tags from the old files imported into the updated versions of those files.
    I found this script which looks like it may solve my problem but I need help fine tuning it for my needs.
    This script takes as input a Music.txt file created with iTunes' File > Export command. It then applies the song ratings found in this file to the same songs in the current iTunes library. The song name, artist, and album must match; otherwise, the rating will not be affected. If they do match, the current rating will be replaced.
    IMPORTANT: Before running this script, the Music.txt file must be encoded as UTF-8. To do so, simply open Music.txt in TextEdit (or a similar editor) and re-save the file with UTF-8 encoding.
    set the_file to Flix Media/Flix Music/All Media/Music.txt
    set music_lines to read the_file using delimiter {return}
    display dialog "This script may take a very long time to run, depending on the size of your iTunes library. (Processing a 2000-song library required approximately 20 minutes on a 2.5 GHz MacBook Pro.)" & return & return & "Do you still want to continue?"
    -- Split the line at tab stops
    set text item delimiters to ASCII character 9
    -- Start at 2 instead of 1 to skip the header line
    repeat with i from 2 to count music_lines
              set music_line to item i of music_lines
              set music_fields to every text item of music_line
              if length of music_fields is 27 then
                        set the_name to item 1 of music_fields
                        set the_artist to item 2 of music_fields
                        set the_album to item 4 of music_fields
                        set the_rating to item 26 of music_fields
                        tell application "iTunes"
                                  set the_tracks to (file tracks of library playlist 1 whose name is the_name and artist is the_artist and album is the_album)
                                  repeat with the_track in the_tracks
                                            set the rating of the_track to the_rating
                                  end repeat
                        end tell
              end if
    end repeat
    Problem 1  
    What am I doing incorrect with my file path?  My computer has a separate partition called Flix Media
    This is what I typed :
    set the_file to Flix Media/Flix Music/All Media/Music.txt
    but it errors out on Flix Media.
    The original script had this:
    set the_file to choose file      
    Problem 2
    I would like to automate this script to run at night. (I have a few scripts that need to run at night prior to this.)
    Is there any way to save the music.text file with an applescript, then re-open it in a textEdit and re-save it as a UTF-8 format?
    It this could be done then the running of this script could follow.
    Any help or ideas would be greatly appriciated....
    Ron

    I just figure what was wrong with my file path.
    set the_file to "Volumes/Flix Media/Flix Music/All Media/Music.txt"
    So all I need is help with problem 2.
    Thanks.....
    Ron

  • Applescript help - can't pass file reference

    Hi - This is doing my head in !
    I have an Automator script that encrypts a PDF and then runs an AppleScript within the Automator workflow. The result of this workflow is a filename I need within another calling Applescript.
    So in the Automator workflow I have the following code:
    set the new_item to (move item target_name of the temp_folder to container of the source_item)
    end tell
    return new_item as alias
    When I view the response in the calling Applescript I see this:
    "{alias \"Macintosh HD:Support:test-28 (encrypted).pdf\"}"
    How do I consume this in my Applescript ?? I need to get it into a POSIX format or something I can use.
    Can anyone help ??

    Sorry - I posted this in the wrong forum. I have reposted in Applescript. Apologies.

  • Need AppleScript help

    Simple Aperture AppleScript question over here http://discussions.apple.com/thread.jspa?threadID=2771467&stqc=true
    Thanks for any help!

    See reply at http://discussions.apple.com/thread.jspa?threadID=2771467&tstart=0&messageID=131 64941#13164941

  • Applescript Help - Automatic Email Send to Group

    Hey guys,
    Me again. Ok, so I am starting to get the hang of this, learning more and more on applescripting. You guys have been a great help.
    Now, I have a little applscript that I want to send an email automatically to a Group in my address book. However for the life of me, I can't figure out how to do that! Or is this just not possible? Please advise!
    Here it is:
    set theToRecipient to "My group" -- this would be the group name of email addresses that is in my address book
    set theSubject to "The subject of the message"
    set theContent to "the content of my message."
    tell application "Mail"
      activate
              set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
              tell newMessage
      make new to recipient at end with properties {address:theToRecipient}
      send newMessage
              end tell
    end tell
    Appreciate all your help.

    Try this --
    set theToRecipient to {}
    tell application "Address Book"
              if group "MyGroup" exists then
                             set theToRecipient to "MyGroup"
              end if
    end tell
    set theSubject to "The subject of the message"
    set theContent to "the content of my message."
    tell application "Mail"
      activate
              set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
              tell newMessage
      make new to recipient at end with properties {address:theToRecipient}
      --send newMessage
              end tell
    end tell

  • Applescript Help for TextEdit

    I want to be able to select each paragraph from a long rtf file and save it in another document.
    Say my doc has 25 paragraphs and I want to get 25 different documents containing each different paragraph.
    Any Help?
    Thanks

    tell application "TextEdit"
    repeat with aParagraph in paragraphs of document 0 as list
    set newDoc to make new document at end of documents
    set text of newDoc to aParagraph
    end repeat
    end tellThis assumes the document you want to extract from is the frontmost document.
    Also, you should use the [Applescript|http://discussions.apple.com/forum.jspa?forumID=724] forum under Mac OS X Technologies.

  • Automator/applescript help needed

    Basically I want to use automator and/or applescript to create a script that will add my current MAC address to a text file i specify (in the script) and then have a popup to enter a new one that also gets logged in the text file and then it changes to the new one. I need a way to paste the contents of the clipboard in to a terminal command. How can I do that?

    Note that Discussions has dedicated AppleScript & UNIX forums in Support > Discussions > Mac OS X Technologies & an Automator one in Support > Discussions > Mac OS X v10.5 Leopard. These would be better places to post if you are looking for detailed help with this.
    That said, take a peek at the man page for pbcopy, which provides Terminal access to the Mac clipboard. The "See Also" section has references to developer info for working with the clipboard.
    Message was edited by: R C-R

Maybe you are looking for