View Full Version : Help with my applescript

May 9, 2012, 05:25 PM
I'm trying to write an applescript that get's the filepath of a .mp3 file in iTunes and shows the corresponding .als file (with the same name) in a folder name ALS in my itunes folder.
This is what i have so far:

tell application "iTunes"
set fileName to {location} of selection of front browser window as string
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pieces to text items of fileName
set fileName to last text item of fileName
set fileName to text 1 thru -5 of fileName
set AppleScript's text item delimiters to TID
set fileName to fileName & ".als"
set fileName to ":Users:nichola:Music:iTunes:ALS:" & fileName
end tell
tell application "Finder"
reveal fileName
end tell

I get this error message:

Finder got an error: Can’t make ":Users:nichola:Music:iTunes:ALS:02 049-Eric Prydz - 2night (Original Mix)_PN.als" into type item.

For some reason: it doesn't successfully reveal the file in finder, I have made sure this file exists in the path it specifies, also i have tried making a new patch with

tell application "Finder"
reveal "(I have dragged the file from folder ALS here)"
end tell

and get the same error message.
I am new to applescript, can somebody tell me what is wrong?

May 9, 2012, 05:54 PM
When using colon-separated directories, the first element must be the disk name eg "Macintosh HD" if that's your actual disk name.

Perhaps also :

tell application "Finder"
reveal fileName as alias
end tell

May 9, 2012, 07:28 PM
thankyou! you have saved me a lot of time..
Also, my next step in the script is to copy this file to the keyoard and paste it into an application.
Is there a way to copy the contents of a file successfully onto the clipboard (not the path)?
It seems that you cannot simply send the path of the file to an application.
When I copy an .als file I want to paste into the application, this is the results from the clipboard:

{{«class furl», 108}, {«class icns», 27289}, {«class ut16», 98}, {«class utf8», 48}, {«class 8BPS», 9736}, {«class BMP », 65590}, {«class TPIC», 8828}, {TIFF picture, 67062}, {«class PNGf», 4718}, {«class jp2 », 4215}, {GIF picture, 2671}, {JPEG picture, 5040}, {string, 48}}

Any advice you can give me? Thanks!

May 9, 2012, 08:15 PM
tell application "iTunes"
set theTrack to item 1 of selection
set loc to theTrack's location
end tell

tell application "Finder"
reveal loc
set fileName to (get name of (loc as alias))
end tell

set the clipboard to fileName

May 9, 2012, 10:16 PM
Apologies if i was unclear in the above post!
What i am trying to do is copy the contents (not filepath) on the clipboard, and paste it into my DAW software. The file i am trying to paste is a .als session file (related to Ableton Live)

Thankyou for your reply Doug! however this script only copies the file name onto the clipboard, and doesn't allow me to copy it into my other software. :(
For now I will just use a keystroke to copy files from Finder. I have tried to make a script to hit Copy with a key command menu. But it doesn't seem to be working:

tell application "System Events"
key code 99 using command down
end tell

I have tried replacing key code with keystroke, nothing happens.
I have made sure "Enable Access for Assistive Devices" is checked under the Universal access of System Preferences.


May 10, 2012, 08:37 AM
Sorry can't help you with your problem related to Ableton Live or DAW software. But can help with your keystroke to copy files from Finder.

Quote from DoughAdams

"System Events" will send a key code or a keystroke to the frontmost application.So, you have to make sure that Finder is frontmost—activate it, in AppleScript parlance

Code will copy whatever is selected in Finder. If you want to finetune that look at selection property in the Finder Basics Suite.

tell application "Finder"
tell application "System Events"
key code 8 using command down
-- or by keystroke
-- keystroke "c" using command down
end tell
end tell


May 13, 2012, 07:07 PM
I'm either clearing things up or I am making thing worse. I'm not sure. I kept reading this thread and I couldn't tell if you were trying to get the contents of the .als file onto the clipboard or if you were trying to get a list of file names on the clipboard. Here is a solution to being able to place the contents (of a text file) onto the clipboard.

set fileRef to open for access "Macintosh HD:Users:numero:Desktop:TestFile.txt"

set theLength to get eof fileRef
set theData to read fileRef from 0 to theLength - 1
set the clipboard to theData

close access fileRef