Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm writing an Apple Script that ultimately will mark commercials for all iTunes exports from EyeTV. But I'm running into a simple problem with AppleScript paths, which the EyeTV app returns as recording locations. Here's the context:

set recordingID to 370404006
set myid to recordingID as integer
tell application "EyeTV"
    set eyetvr_file to get the location of recording id myid as alias
end tell
return eyetvr_file

alias "Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr"

Now I need to extract the containing path and the file prefix 000000001613eaa6 (using this question) so I can look for the corresponding commercial markings in the file 000000001613eaa6.edl. Here's the hiccup:

tell application "Finder"
    set eyetv_path to container of eyetvr_file
    set root_name to name of eyetvr_file
    set fext to name extension of eyetvr_file
end tell

The results are,

eyetv_path: document file "South Park.eyetv" of folder "EyeTV Archive" of folder "Documents" of disk "Macintosh HD2" of application "Finder"

root_name: "000000001613eaa6.eyetvr"

fext: ""

fext should be ".eyetvr", not the empty string. How do I correctly extract ".eyetvr" from either eyetvr_file or root_name? I've tried a bunch of hack like

set fext to name extension of (eyetvr_file as document)

But this gives error like,

error "Can’t make alias \"Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr\" into type document." number -1700 from alias "Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr" to document

share|improve this question
up vote 1 down vote accepted

Finder doesn't recognize all filename extensions. You could just use text item delimiters to remove the last part though.

do shell script "touch /tmp/some.file.eyetvr"
set text item delimiters to "."
tell application "Finder"
    set n to name of file (POSIX file "/tmp/some.file.eyetvr")
    if n contains "." then set n to (text items 1 thru -2 of n) as text
    n -- some.file
end tell
share|improve this answer
    
Thanks! This works perfectly with the edits below, and provides a better solution that the one I linked to. This code gave me an error unless I specified "AppleScript's text item delimiters", and I also saved the previous settings for use in a larger code block: "set delims to AppleScript's text item delims <br> set AppleScript's text item delimiters to "." <br> &hellip; set AppleScript's text item delimiters to delims" – stvs Oct 16 '12 at 14:23

Mini-comments apparently do not allow posting code, so here are my edits to Lauri Ranta's nice solution:

do shell script "touch /tmp/some.file.eyetvr"
set delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
tell application "Finder"
    set n to name of file (POSIX file "/tmp/some.file.eyetvr")
    if n contains "." then set n to (text items 1 thru -2 of n) as text
    n -- some.file
end tell
set AppleScript's text item delimiters to delims

I'll post a link to the EyeTV-commercial-marking-script-for-iOS when I've finished that project.

share|improve this answer
    
Here's a link to the resulting AppleScript, ExportDone.scpt: code.google.com/p/etv-comskip/downloads/… – stvs Oct 20 '12 at 2:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.