Applescript - Get folder name and copy

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Applescript - Get folder name and copy Mon Aug 20, 2012 8:18 pm • by eiff
Code: Select all
tell application "Finder"
   set parentFolder to name of container of (theFile)
   display dialog parentFolder as text
   set newfolder to "Macintosh HD:Users:david:Dropbox:shares:yx public:Teaching Stuff" & ":" & parentFolder
   display dialog newfolder as text
   move theFile to newfolder
end tell


I'm super new to applescript, but what I'm trying to do is move theFile to the folder with the same name as it's parent folder. Kinda weird, but it's acting as a sort of 'selective sync'.

Any ideas why this is giving me an error. The variables look like they're popping up right.

Thanks,
- David
eiff
 
Posts: 7
Joined: Mon Aug 20, 2012 8:14 pm

Re: Applescript - Get folder name and copy Mon Aug 20, 2012 11:59 pm • by flynn
What you are doing doesn't require applescript.

First, you would match the file with hazel using whatever rules you are using.
Then, you would move the file to the specified folder using hazel, not applescript.
After that, you would use the "sort into subfolder" using the "source folder" attribute. There, you can choose from the whole path to the file, or just the path from the matched folder to the file. You would choose the second option (aka use path from monitored folder).

So your rules will be something like this:

Code: Select all
if...
(rules)
Move file to folder "Macintosh HD:users:david:dropbox:shares:yx public:teaching stuff:"
sort into subfolder with pattern "source folder"


Should work
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: Applescript - Get folder name and copy Tue Aug 21, 2012 8:59 am • by eiff
YES!!!
Thanks flynn!

Worked like a charm. It's amazing the stuff you can do with hazel's built in functionality, you just have to get your head round the way it thinks. :)

Thanks again,
eiff
 
Posts: 7
Joined: Mon Aug 20, 2012 8:14 pm


Return to Support