The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   Applescript: Create relative paths (http://hintsforums.macworld.com/showthread.php?t=71704)

rmurphy07 04-30-2007 03:21 PM

Applescript: Create relative paths
 
I am trying to get this script to remove the path name to the mp3 file. Here's the entire script, but the trouble is particularly in section 4. Right now, it outputs an m3u file, but has absolute paths. I am working on making a portable playlist script. Here it is. Any help would be greatly appreciated.

Code:

-- 1. THIS SETS THE NAME OF THE PLAYLIST
tell application "iTunes"
        activate
        play
        stop
        set thePlaylist to the name of current playlist
        set theList to every track in the playlist thePlaylist
end tell

-- 2. THIS IS A CHARACTER FIND AND REPLACE ROUTINE WHICH I DON'T UNDERSTAND

on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars

on getTimeinSec(theTime)
        set AppleScript's text item delimiters to ":"
        set theTime to theTime's text items
        set AppleScript's text item delimiters to ""
       
        set MintoSec to ((the first item in theTime) * 60)
       
        set theTime to MintoSec + the (second item in theTime)
       
        return theTime
       
end getTimeinSec

set newlinechar to "
" as string

set theItems to ""

-- 3. SET DESTINATION FOR FILES & M3U FILE

tell application "iTunes"
        tell application "Finder"
                set makeFolder to do shell script ¬
                        "mkdir -v ~/Desktop/" & thePlaylist
                set theFolder to POSIX file makeFolder as alias
        end tell
        repeat with theTrack in theList
                set theTrackName to ((the location of theTrack)) -- may need to coerce to alias for OS 9
                log theTrackName
                tell application "Finder"
                        try
                                duplicate file theTrackName to theFolder
                        on error
                                tell application "iTunes"
                                        display dialog "The Finder reported an error: The file [" & (theTrackName as string) & "] could not be copied to [" & theFolder & "]." with icon caution
                                end tell
                        end try
                end tell
        end repeat
       
-- 4. THIS GETS THE INFO FROM iTUNES & CLEANS UP THE NAMES
       
        repeat with theTrack in (get every track of playlist thePlaylist)
                set theTitle to (name of theTrack) as string
                set theArtist to (artist of theTrack) as string
                set trackSeconds to getTimeinSec(time of theTrack) of me as string
                set theFiles to (location of theTrack)
                set theFiles1 to get quoted form of POSIX path of (theFiles as alias)
                set theFiles2 to do shell script ¬
                        "ls " & theFiles1
                set cleanArtist to replace_chars(theArtist, " ", "_") of me
               
                set cleanTitle to replace_chars(theTitle, "&", "%26") of me
                set cleanTitle to replace_chars(cleanTitle, "(", "") of me
                set cleanTitle to replace_chars(cleanTitle, ")", "") of me
                set cleanTitle to replace_chars(cleanTitle, "!", "") of me
                set cleanTitle to replace_chars(cleanTitle, " ", "_") of me
                set cleanTitle to replace_chars(cleanTitle, "'", "%27") of me
               
               
                set theItems to theItems & newlinechar & "#EXTINF:" & trackSeconds & "," & theTitle & " - " & theArtist & newlinechar & theFiles2
               
        end repeat
       
-- .5 THIS ACTIVATES TERMINAL TO CREATE THE ACTUAL M3U FILE. HILARITY ENSUES.
        get POSIX path of (theFolder as alias)
        copy result as text to theNew
        tell application "Terminal"
                launch
                activate
                tell application "System Events"
                        keystroke "cd /" & theNew
                        keystroke return
                        keystroke "nano" & " " & thePlaylist & ".m3u"
                        keystroke return
                        delay 0.5
                        keystroke "#EXTM3U"
                        keystroke return
                        keystroke theItems
                        keystroke "x" using control down
                        keystroke "y"
                        keystroke return
                        keystroke "killall Terminal"
                        keystroke return
                       
                end tell
        end tell
end tell


cwtnospam 04-30-2007 04:35 PM

This seems to work:

Replace this line:

Code:

set theFiles2 to do shell script ¬
                        "ls " & theFiles1

with this one:

Code:

                                set theFiles2 to name of (info for theFiles)

rmurphy07 04-30-2007 04:41 PM

Hey,
Thanks for the quick replies.

The first suggestion only yielded the track name instead of the file name

The second suggestion yielded this:
Quote:

Can't make {name:"01 Lesson One.mp3", creation date:date "Wednesday, February 14, 2007 3:48:19 PM", modification date:date "Wednesday, February 14, 2007 3:48:33 PM", icon position:{0, 0}, size:1.159122E+6, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"mp3", displayed name:"01 Lesson One.mp3", default application:alias "iBookHD:Applications:iTunes.app:", kind:"MP3 Audio File", file type:"MPG3", file creator:"hook", type identifier:"public.mp3", locked:false, busy status:false, short version:"", long version:""} into type string.
Thank you so much though! :)

cwtnospam 04-30-2007 04:57 PM

1 Attachment(s)
Maybe I'm not following what you're trying to do. I ran it on my system with the line: set theFiles2 to name of (info for theFiles) and got the results below:

#EXTM3U

#EXTINF:536,Lifes Been Good - Joe Walsh
Lifes Been Good.mp3
#EXTINF:196,Jimmy Buffett - Changes in Latitudes, Changes in Attitudes -
#-
Jimmy Buffett - Changes in Latitudes, Changes in Attitudes.mp3
#EXTINF:138,(The Theme From) The Monkees - The Monkees
(The Theme From) The Monkees.mp3
#EXTINF:144,(I'm Not Your) Steppin' Stone - The Monkees - The Monkees
(I'm Not Your) Steppin' Stone.m4p




See attached file as well.


By the way, I was able to import the playlist and use it.

rmurphy07 04-30-2007 04:59 PM

Wow. That is exactly what I am trying to do. The error I got popped up in the Script Editor window. Maybe I didn't modify my code correctly?

cwtnospam 04-30-2007 05:01 PM

Be sure not to touch the keyboard while it's running. I've messed up a few runs by trying to tab between applications while it's running.

rmurphy07 04-30-2007 05:03 PM

Would you mind posting what your code looks like? I tried it again, but it still gave me that error.

cwtnospam 04-30-2007 05:04 PM

Code:

-- 1. THIS SETS THE NAME OF THE PLAYLIST
tell application "iTunes"
        activate
        play
        stop
        set thePlaylist to the name of current playlist
        set theList to every track in the playlist thePlaylist
end tell

-- 2. THIS IS A CHARACTER FIND AND REPLACE ROUTINE WHICH I DON'T UNDERSTAND

on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars

on getTimeinSec(theTime)
        set AppleScript's text item delimiters to ":"
        set theTime to theTime's text items
        set AppleScript's text item delimiters to ""
       
        set MintoSec to ((the first item in theTime) * 60)
       
        set theTime to MintoSec + the (second item in theTime)
       
        return theTime
       
end getTimeinSec

set newlinechar to "
" as string

set theItems to ""

-- 3. SET DESTINATION FOR FILES & M3U FILE

tell application "iTunes"
        tell application "Finder"
                set makeFolder to do shell script ¬
                        "mkdir -v ~/Desktop/" & thePlaylist
                set theFolder to POSIX file makeFolder as alias
        end tell
        repeat with theTrack in theList
                set theTrackName to ((the location of theTrack)) -- may need to coerce to alias for OS 9
                log theTrackName
                tell application "Finder"
                        try
                                duplicate file theTrackName to theFolder
                        on error
                                tell application "iTunes"
                                        display dialog "The Finder reported an error: The file [" & (theTrackName as string) & "] could not be copied to [" & theFolder & "]." with icon caution
                                end tell
                        end try
                end tell
        end repeat
       
        -- 4. THIS GETS THE INFO FROM iTUNES & CLEANS UP THE NAMES
       
        repeat with theTrack in (get every track of playlist thePlaylist)
                set theTitle to (name of theTrack) as string
                set theArtist to (artist of theTrack) as string
                set trackSeconds to getTimeinSec(time of theTrack) of me as string
                set theFiles to (location of theTrack)
                set theFiles1 to get quoted form of POSIX path of (theFiles as alias)
                set theFiles2 to name of (info for theFiles)
                --set theFiles2 to do shell script ¬
                --        "ls " & theFiles1
                set cleanArtist to replace_chars(theArtist, " ", "_") of me
                set cleanTitle to replace_chars(theTitle, "&", "%26") of me
                set cleanTitle to replace_chars(cleanTitle, "(", "") of me
                set cleanTitle to replace_chars(cleanTitle, ")", "") of me
                set cleanTitle to replace_chars(cleanTitle, "!", "") of me
                set cleanTitle to replace_chars(cleanTitle, " ", "_") of me
                set cleanTitle to replace_chars(cleanTitle, "'", "%27") of me
               
                set theItems to theItems & newlinechar & "#EXTINF:" & trackSeconds & "," & theTitle & " - " & theArtist & newlinechar & theFiles2
        end repeat
       
        -- .5 THIS ACTIVATES TERMINAL TO CREATE THE ACTUAL M3U FILE. HILARITY ENSUES.
        get POSIX path of (theFolder as alias)
        copy result as text to theNew
        tell application "Terminal"
                launch
                activate
                tell application "System Events"
                        keystroke "cd /" & theNew
                        keystroke return
                        keystroke "nano" & " " & thePlaylist & ".m3u"
                        keystroke return
                        delay 0.5
                        keystroke "#EXTM3U"
                        delay 1
                        keystroke return
                        keystroke theItems
                        keystroke "x" using control down
                        keystroke "y"
                        keystroke return
                        --keystroke "killall Terminal"
                        keystroke return
                       
                end tell
        end tell
end tell

I just noticed that I left out the killall Terminal command. I don't think that changes anything though!

cwtnospam 04-30-2007 05:52 PM

Did that work for you?

rmurphy07 04-30-2007 06:13 PM

Yes! thanks!!

tw 05-01-2007 01:48 AM

just as an aside, if I can offer some (unsolicited) applescripting tips... :)

you use shell scripting more than is necessary. it doesn't hurt anything, of course, it just makes your code slow and difficult to follow. for instance, where you use:
Code:

tell application "Finder"
        set makeFolder to do shell script "mkdir -v ~/Desktop/" & thePlaylist
        set theFolder to POSIX file makeFolder as alias
end tell

this would do the same:
Code:

set DTpath to (path to desktop)
tell application "Finder" to make new folder at DTpath ¬
        with properties {name:thePlaylist}

and here you use:
Code:

set theFiles to (location of theTrack)
set theFiles1 to get quoted form of POSIX path of (theFiles as alias)
set theFiles2 to do shell script "ls " & theFiles1

when all you need is this:
Code:

set theFiles2 to (location of theTrack) as text
    -- for ':' style file spec

    -- or --

set theFiles2 to POSIX path of ((location of theTrack) as alias)
    -- for '/' style file spec

you can dispense with the getTimeinSec() function entirely, because iTunes already gives you a duration property that lists out track length in seconds (e.g. use set trackSeconds to duration of theTrack as string)

you also have some serious nesting issues - at one point you have applescript telling iTunes to tell the Finder to tell iTunes to display a dialog. I'm sure it works, but if you were doing something more complicated it would probably start giving you errors. Use tell blocks when you need to and end them as quickly as you can; and try to avoid nested tells unless you just can't. For instance, I'd rewrite part of your script like this:
Code:

tell application "iTunes"  -- get playlist info
    set titleList to name of every track of thePlaylist
    set artistList to artist of every track of thePlaylist
    -- etc., etc...
    -- probably still need a loop for the locations,
    -- because there's a calculation in it

end tell
repeat
    -- do all of your replace_char() commands here,
    -- as well as building your text strings,
    -- outside of the iTunes and Finder tells

end repeat
tell application "Finder"
    -- first make the folder, as above
    -- then copy the files, using the list
    -- of file locations you made in the iTunes tell

end tell

the GUI scripting of terminal you use is artful, but it's a headache waiting to happen. and it's unnecessary - something like this would be much stabler, and quicker.
Code:

set fileBody to "#EXTM3U" & return & theItems
set fileName to thePlaylist & ".m3u"
set filePointer to open for access (theFolder & fileName) with write permission
write fileBody to filePointer
close access filePointer

hope there's something useful for you here... :D

rmurphy07 05-01-2007 10:03 AM

Yeah! That's great!

I did try

Code:

set DTpath to (path to desktop)
tell application "Finder" to make new folder at DTpath ¬
        with properties {name:thePlaylist}

in a previous build of this, but it didn't work. I really appreciate your insight and may slim down this script. It does help me in the future, as I've been hit & miss with writing applescripts. Thanks again.

So, I just tried to replace those code snippets (one at a time of course) and none of them seemed to work. But I wouldn't mind some insight on my "nesting" problem. That seems easier to figure out.

tw 05-01-2007 12:32 PM

which code snipps didn't work? I don't think I was using anything non-standard...

as for nesting, applescript is a programing language designed to extend itself by picking up capabilities from other applications. when you want to tap into an application's special abilities, you use a Tell block to tell the application to do it, and then give the result back to applescript. so if you wanted to know what percent of a playist a particular track represented:
Code:

set plName to "cool sounds"
tell application "iTunes"
    -- use iTunes' special abilities here
    set listTime to duration of playlist plName
    set trackTime to duration of track 27 of playlist plName
end tell
-- nothing below needs iTunes' special abilities, so exit the tell block
set thePercent to trackTime/listTime*100
display dialog "Track 27 is " & thePercent & " of playlist " & plName

this will display the dialog in the script context. if you want to display the dialog while still in iTunes, then you need to move the display dialog command back into the tell block.

code like the following is problematic
Code:

tell application "Itunes"
    tell application "Finder"
          set listTime to duration of playlist plName
          display dialog listTime
    end tell
end tell

because (first) the property duration is not really a property of the Finder, it's something specific to iTunes, and (second) you are effectively running the Finder from within iTunes for the purposes of this command - confusing to read, and it makes the system jump hoops. you might occasionally want to do something like this:
Code:

tell application "Itunes"
    set listTime to duration of playlist plName
    tell me to display dialog listTime
end tell

the tell me command will force the dialog to appear in the script context rather than iTunes. but in this case I'd probably just move the Display Dialog out of the tell block.

there are things called OSAX (or scripting additions) that add functionality to applescript directly, without calling applications. for instance, the open for access command I used is part of the Standard Additions osax (included by apple in every install). you can get more at places like MacScripter.net, but be a little cautious, because not all of the third party ones are well-written, and they can interfere with each other.

rmurphy07 05-02-2007 03:32 PM

I tried to implement the code snippets that cwtnospam kindly provided. I replaced them and tested them one at a time. However, none of them seemed to work. Would someone mind compiling a functioning copy of this script for me to study? That's how I've been learning applescript: by studying other peoples scripts. Unfortunately, it sounds like I've picked up most of their bad habits. Thanks.

cwtnospam 05-02-2007 03:41 PM

Do you mean that tw provided? Which don't work?

cwtnospam 05-02-2007 04:21 PM

I've made some of the tw's suggestions here in the code below. I'd have to spend more time figuring out all the logic, but I'm sure that tw is correct that there is room to simplify and streamline the code.

Code:

-- 1. THIS SETS THE NAME OF THE PLAYLIST
tell application "iTunes"
        activate
        play
        stop
        set thePlaylist to the name of current playlist
        set theList to every track in the playlist thePlaylist
end tell
-- 2. THIS IS A CHARACTER FIND AND REPLACE ROUTINE WHICH I DON'T UNDERSTAND

on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars

on getTimeinSec(theTime)
        set AppleScript's text item delimiters to ":"
        set theTime to theTime's text items
        set AppleScript's text item delimiters to ""
       
        set MintoSec to ((the first item in theTime) * 60)
       
        set theTime to MintoSec + the (second item in theTime)
       
        return theTime
       
end getTimeinSec

set newlinechar to "
" as string

set theItems to ""

-- 3. SET DESTINATION FOR FILES & M3U FILE

tell application "iTunes"
        tell application "Finder"
                set DTpath to path to the desktop folder
                make new folder at DTpath ¬
                        with properties {name:thePlaylist}
                set theFoldera to DTpath & thePlaylist as string
                set theFolder to theFoldera as alias
        end tell
        repeat with theTrack in theList
                set theTrackName to ((the location of theTrack)) -- may need to coerce to alias for OS 9
                log theTrackName
                tell application "Finder"
                        try
                                duplicate file theTrackName to theFolder
                        on error
                                tell application "iTunes"
                                        display dialog "The Finder reported an error: The file [" & (theTrackName as string) & "] could not be copied to [" & theFolder & "]." with icon caution
                                end tell
                        end try
                end tell
                tell application "iTunes"
                        -- 4. THIS GETS THE INFO FROM iTUNES & CLEANS UP THE NAMES
                        set theTitle to (name of theTrack) as string
                        set theArtist to (artist of theTrack) as string
                        set trackSeconds to getTimeinSec(time of theTrack) of me as string
                        set theFiles to (location of theTrack)
                        set theFiles2 to name of (info for theFiles)
                        set cleanArtist to replace_chars(theArtist, " ", "_") of me
                        set cleanTitle to replace_chars(theTitle, "&", "%26") of me
                        set cleanTitle to replace_chars(cleanTitle, "(", "") of me
                        set cleanTitle to replace_chars(cleanTitle, ")", "") of me
                        set cleanTitle to replace_chars(cleanTitle, "!", "") of me
                        set cleanTitle to replace_chars(cleanTitle, " ", "_") of me
                        set cleanTitle to replace_chars(cleanTitle, "'", "%27") of me
                       
                        set theItems to theItems & newlinechar & "#EXTINF:" & trackSeconds & "," & theTitle & " - " & theArtist & newlinechar & theFiles2
                       
                end tell
        end repeat
        -- MOVED SECTION 4 INTO SECTION THREE, SINCE THE SAME LOOP DOESN'T NEED TO BE REPEATED
        -- 4. THIS GETS THE INFO FROM iTUNES & CLEANS UP THE NAMES
       
        --repeat with theTrack in (get every track of playlist thePlaylist)
        --set theTitle to (name of theTrack) as string
        --set theArtist to (artist of theTrack) as string
        --set trackSeconds to getTimeinSec(time of theTrack) of me as string
        --set theFiles to (location of theTrack)
        --set theFiles2 to name of (info for theFiles)
        --set cleanArtist to replace_chars(theArtist, " ", "_") of me
        --set cleanTitle to replace_chars(theTitle, "&", "%26") of me
        --set cleanTitle to replace_chars(cleanTitle, "(", "") of me
        --set cleanTitle to replace_chars(cleanTitle, ")", "") of me
        --set cleanTitle to replace_chars(cleanTitle, "!", "") of me
        --set cleanTitle to replace_chars(cleanTitle, " ", "_") of me
        --set cleanTitle to replace_chars(cleanTitle, "'", "%27") of me
       
        --set theItems to theItems & newlinechar & "#EXTINF:" & trackSeconds & "," & theTitle & " - " & theArtist & newlinechar & theFiles2
        --end repeat
       
        -- .5 THIS ACTIVATES TERMINAL TO CREATE THE ACTUAL M3U FILE. HILARITY ENSUES.
        get POSIX path of (theFolder as alias)
        copy result as text to theNew
        tell application "Terminal"
                launch
                activate
                tell application "System Events"
                        keystroke "cd /" & theNew
                        keystroke return
                        keystroke "nano" & " " & thePlaylist & ".m3u"
                        keystroke return
                        delay 0.5
                        keystroke "#EXTM3U"
                        delay 1
                        keystroke return
                        keystroke theItems
                        keystroke "x" using control down
                        keystroke "y"
                        keystroke return
                        keystroke "killall Terminal"
                        keystroke return
                       
                end tell
        end tell
end tell


NovaScotian 05-02-2007 05:23 PM

Somebody didn't understand this:

Code:

on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        set this_text to the item_list as string
        set AppleScript's text item delimiters to ""
        return this_text
end replace_chars

AppleScript's text item delimiters are a property of AppleScript itself. They persist once set to a text string, default to "".

A text item delimiter is how AppleScript divides up a string into parts. Since the default value is "", i.e. nada, the text items of a string are simply its characters with nothing between.

When you set text item delimiters, you are telling AS to divvy up the string into chunks separated by those delimiters, so the text items are presented in an AppleScript list of the chunks of text as they occur between the delimiters you have set.

Similarly, if you reassemble a list of text items by coercing the list to a string, AppleScript will insert its current text item delimiters between the elements of the list as it reassembles a string.

The code fragment above works as follows:

set AppleScript's text item delimiters to the search_string
--> the word or symbol we want to find in the text.
set the item_list to every text item of this_text
--> a list of strings of text that occur between the instances of search_string
set AppleScript's text item delimiters to the replacement_string
--> change the delimiters from search_string to replacement_string
set this_text to the item_list as string
--> coerce the list back to a string, inserting the replacement_string between each item in the item_list.
set AppleScript's text item delimiters to ""
--> set them back to the default (they're persistent).

A better way to do this in a handler is as follows:

set tid to applescript's text item delimiters -- preserve the current state
set applescript's text item delimiters to search_string
set myList to text items of whatever
set applescript's text item delimiters to replace_string
set myNewText to myList as string
set applescript's text item delimiters to tid -- set them back where they were.

This is better because it preserves the state in the code that called the handler, in case it was not "".

tw 05-02-2007 10:31 PM

ok, normally this is supposed to be a hints forum - :) - but since you're looking for example code, here's a working version, with some tweaks. anything completely incomprehensible, ask.

Code:

on run
        tell application "iTunes"
                set playlistName to name of view of browser window 1
                set thePlaylist to playlist playlistName
                -- store everything as lists
                -- might be better to use 'file track' instead of 'track' in these
                set theList to every track in thePlaylist
                set titleList to name of every track in thePlaylist
                set artistList to artist of every track in thePlaylist
                set trackSeconds to duration of every track in thePlaylist
                set theFiles to location of every track in thePlaylist
        end tell
       
        set theItems to ""
        repeat with i from 1 to count of theList
                -- retrieve items from lists, clean and build the big string to be saved
                set tid to AppleScript's text item delimiters
                -- store old tid here once, rather than repeatedly in the subroutine
                set theTime to round (item i of trackSeconds)
                set theArtist to item i of artistList
                set theTitle to item i of titleList
                set findList to {"&", "(", ")", "!", " ", "'"}
                set replList to {"%26", "", "", "", "_", "%27"}
                repeat with j from 1 to length of findList
                        set theTitle to replace_chars(theTitle, item j of findList, item j of replList)
                end repeat
                set theArtist to replace_chars(theArtist, " ", "_")
                set AppleScript's text item delimiters to tid
                -- restore old tid here once, rather than repeatedly in the subroutine
                set theFile to POSIX path of (item i of theFiles)
                set theItems to theItems & "#EXTINF:" & theTime & "," & theTitle & " - " & theArtist & return & theFile & return
        end repeat
       
        set DTopPath to (path to desktop)
        tell application "Finder"
                try
                        set folderPath to (make new folder at DTopPath with properties {name:playlistName}) as alias
                on error
                        -- folder already exists, so just point to it
                        set folderPath to (DTopPath as text) & playlistName & ":"
                end try
                (*
                not sure why you want to duplicate all the mp3 file to this folder. playlists ¬
                usually point to the master version in the user library extra copies like this ¬
                are not needed.  are you copying these playlists to another machine? But ¬
                here you go, if you want it...
        *)
                duplicate theFiles to folderPath
        end tell
       
        set fileBody to "#EXTM3U" & return & theItems
        set fileName to playlistName & ".m3u"
        set fp to open for access (folderPath & fileName) as text with write permission
        write fileBody to fp
        close access fp
        display alert "WhooHoo...!" as informational
end run

on replace_chars(this_text, search_string, replacement_string)
        set AppleScript's text item delimiters to the search_string
        set the item_list to every text item of this_text
        set AppleScript's text item delimiters to the replacement_string
        return item_list as text
end replace_chars


rmurphy07 05-05-2007 04:13 PM

Thanks everyone, I really appreciate the help. It really helps me to see what the code should look like. I hope I can help others with what I learn. Thanks again!

rmurphy07 05-08-2007 06:43 PM

So, I've been too busy to work on the code lately, but had a moment in class tonight.

This line:
Code:

duplicate theFiles to folderPath
kicks out this error:

Quote:

Finder got an error: Can't set "rmurphy:Desktop:test:" to {alias "rmurphy: My files:Academic:2007 spring:NTX:Greek:Audio:Greek -NT Dobson:Learn New Testament Greek:01 Lesson One.mp3", alias "rmurphy: My files:Academic:2007 spring:NTX:Greek:Audio:Greek -NT Dobson:Learn New Testament Greek:02 Lesson Two.mp3", alias "rmurphy: My files:Academic:2007 spring:NTX:Greek:Audio:Greek -NT Dobson:Learn New Testament Greek:03 Lesson Three.mp3"}.
Which looks like it's having trouble aliasing the files?

The point of this script is so that people will be able to create "portable playlists": a folder with all the tracks and the respective m3u file. That way they can place their portable playlist folder in our media server to share.

cwtnospam 05-08-2007 09:05 PM

Just a guess, but it seems to me that the folder already exists in this case,
and the line under the 'on error':

set folderPath to (DTopPath as text) & playlistName & ":"

should be:

set folderPath to (DTopPath as text) & playlistName & ":" as alias


All times are GMT -5. The time now is 05:51 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.