Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fhill2

macrumors newbie
Original poster
May 9, 2012
19
0
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:


Code:
tell application "iTunes"
	activate
	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"
	activate
	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

Code:
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?
Thankyou!
 
Last edited by a moderator:
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 :

Code:
tell application "Finder"
activate
reveal fileName as alias
end tell
 
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!
 
Last edited:
Code:
tell application "iTunes"
	set theTrack to item 1 of selection
	set loc to theTrack's location
end tell

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

set the clipboard to fileName
 
Last edited:
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:
Code:
	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.

Thanks!
 
Last edited by a moderator:
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.

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

http://softwares.bajram.com/downloads/?server=01&file=Full_Key_Codes.dmg
 

Attachments

  • Picture 3.png
    Picture 3.png
    23.3 KB · Views: 536
Contents of file to clipboard

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.


Code:
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.