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

swwack91

macrumors 6502a
Original poster
Jan 28, 2007
736
23
New Jersey
Hi all,

I'm a newbie to the world of AppleScript, but I'm trying to put together a pretty simple script to parse apart a file path and create a .txt file at the end.

For example, the source file path would be:
/Users/Matt/Desktop/3840x2160

I would want to create separate variables from Users, Matt, Desktop, and 3840x2160. From there, I want to create a text document to fill in the blanks with those variables.

For example:
scriptname -tag (Original file path) -tag /Volumes/drive/(variable) -tag 3840x2160.zip

What's the simplest route to break apart the path and then put it back together in a new way?
 
AppleScript is probably the most hellish way to attack this. Unless you really, really need an AppleScript droplet at the end of this project.

Personally, I think you'd have an easier time doing it in python. At least there, you have nice functions that are meant for this sort of path manipulation. Bash scripting can also do something like this in a pinch, but it's a little more involved. And in both cases, Stack Overflow has some good answers to get you going.
 
I think you're crossing an important line here. Splitting a string with a known delimiter is a no-brainer in most languages. Putting the n results into an array is, again, totally straightforward.

But having a different number of variables (named, non-array variables like var1, var2...), based on some arbitrary input - that's called metaprogramming. Definitely not a newbie technique.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.