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

MacBook MH

macrumors member
Original poster
Mar 7, 2009
76
0
Hi,
I want my app to work on every Mac, and open a file which every Mac has in the same location.

here is what I got in AppleScript:

tell application "RandomApp" to open POSIX file "/Users/Martin/Music/iTunes/Random file"


i want to somehow delete the /Users/Martin so it works on different usernames as Martin.

Thanks in advance :D
 
The Standard Additions Library provides you some "special folders" you are able to use in your skript without addressing a special application.

So try with:
Code:
set theFile to (path to home folder as text) & "Random file"
tell application "RandomApp"
        open (POSIX path of theFile)
end tell

You even have a special folder named "music folder" so you can play some song from there randomly:

Code:
set musicFiles to every file of (path to music folder) as list
tell application "iTunes"
	set theFile to some item of musicFiles
	open theFile
end tell
 
What should I do? Please little more detail. I don't understand. Isn't there a easy way just to remove /Users/Martin/
?

Little more detail:
if outcome is equal to "Other machine(s)" then
tell application "TextEdit" to open POSIX file "/Users/Martin/Music/iTunes/iTunes Music Library.xml"
end if

i want the red part away... every mac has its iTunes Music Library.xml in the same location.... so what is the problem? It doesn't matter to me how its done... but i need it without the users/martin to run it on other users too.

:) thanks
 
Ok.

Try this ...

Code:
set TheFileFolder to path to music folder as string
set TheFileFolder to TheFileFolder & "iTunes:iTunes Music Library.xml"
tell application "TextEdit" to open file TheFileFolder
 
Would

Code:
tell application "TextEdit" to open POSIX file "~/Music/iTunes/iTunes Music Library.xml"

work?

This didn't work because AS doesn't take POSIX style file references in open commands and you'd need a single quote around "iTunes Music Library.xml" because of the spaces.

This should work:

Code:
set filePath to "~/Music/iTunes/"

set fileName to "iTunes Music Library.xml"

set newFilePath to filePath & quoted form of (fileName)

do shell script "open " & newFilePath

mt
 
This didn't work because AS doesn't take POSIX style file references in open commands and you'd need a single quote around "iTunes Music Library.xml" because of the spaces.

This should work:

Code:
set filePath to "~/Music/iTunes/"

set fileName to "iTunes Music Library.xml"

set newFilePath to filePath & quoted form of (fileName)

do shell script "open " & newFilePath

mt

Ah. Of course!

Like the OP, I'm newish to Applescript and can quite happily admit that my shell-scripting is very, very, rusty these days.

Cheers.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.