Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > AppleScript Coding Question...

AppleScript Coding Question...
Thread Tools
Dedicated MacNNer
Join Date: Jul 2001
Location: S.P.Q.R.
Status: Offline
Reply With Quote
Feb 19, 2006, 10:51 PM
 
Simply trying to copy files from my iDisk Public folder to their corresponding folder on my HD, and then delete the files on the iDisk. Unfortunately, it keeps trashing the "FOLDERS" (along with the files) on my iDisk.

tell application "Finder"

set fold_path to folder "II. Bill of Particulars" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of disk "iDisk"

set fold_path2 to folder "II. Bill of Particulars" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk

duplicate every file of fold_path to fold_path2

select every file of fold_path
delete selection

end tell
tell application "Finder"

set fold_path3 to folder "III. Correspondence" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of disk "iDisk"

set fold_path4 to folder "III. Correspondence" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk

duplicate every file of fold_path3 to fold_path4

select every file of fold_path3
delete selection

end tell
tell application "Finder"

set fold_path5 to folder "IV. Disc/Stips/Misc" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of disk "iDisk"

set fold_path6 to folder "IV. Disc/Stips/Misc" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk

duplicate every file of fold_path5 to fold_path6

select every file of fold_path5
delete selection

end tell
tell application "Finder"

set fold_path9 to folder "VIII.Write-ups" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of disk "iDisk"

set fold_path10 to folder "VIII.Write-ups" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk

duplicate every file of fold_path9 to fold_path10

select every file of fold_path9
delete selection

end tell

Can someone help me out?
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 20, 2006, 07:08 AM
 
Hmmm - I tried to reproduce your problem - but it worked fine on my machine - the folders on the idisk were not deleted....

Here's the script I used - does it work for you?

Code:
to suckDownFiles(remoteLocation, localLocation) tell application "Finder" duplicate every file of remoteLocation to localLocation select every file of remoteLocation move selection to the trash -- since it's a remote disk this will delete them immediately... end tell end suckDownFiles set desk to path to desktop as alias tell application "Finder" set theiDisk to last disk whose format is WebDAV format set testLocalFolder to folder "ASTest" of desk as alias set testRemoteFolder to folder "ASTest" of folder "Public" of theiDisk my suckDownFiles(testRemoteFolder, testLocalFolder) end tell
     
Dedicated MacNNer
Join Date: Jul 2001
Location: S.P.Q.R.
Status: Offline
Reply With Quote
Feb 20, 2006, 08:01 AM
 
Thank you for the response. I'm sorry but I forgot to mention that this is the first script I've ever written to do this kind of thing. In other words, I don't know what parts your code to customize so it works on my puter.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 20, 2006, 09:53 AM
 
No worries - the top section [the suckDownFiles() part] is a routine/function that does the downloading & deleting. The benefit of turning that into a routine is that you can call the routine several times with different folders - so you don't have to have all that duplicated code.

The bottom section is just a quick test of the routine. I set the parameters in two variables (set testLocalFolder and set testRemoteFolder) then call the routine.

So if you wanted to adapt it for your own purposes you'd want to do something like this:

Code:
to suckDownFiles(remoteLocation, localLocation) tell application "Finder" duplicate every file of remoteLocation to localLocation select every file of remoteLocation move selection to the trash -- since it's a remote disk this will delete them immediately... end tell end suckDownFiles set desk to path to desktop as alias tell application "Finder" set theiDisk to last disk whose format is WebDAV format --Writeups set iDiskFolder to folder "VIII.Write-ups" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of of theiDisk set localFolder to folder "VIII.Write-ups" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk my suckDownFiles(iDiskFolder, localFolder) --Bill of Particulars set iDiskFolder to folder "II. Bill of Particulars" of folder "ALLEN" of folder "*** GOJO ***" of folder "Public" of of theiDisk set localFolder to folder "II. Bill of Particulars" of folder "Allen" of folder " ** CASES **" of folder " Lounge" of folder "Documents" of folder "trains" of folder "Users" of startup disk my suckDownFiles(iDiskFolder, localFolder) --you can repeat this for as many folders as you want.... end tell
     
Dedicated MacNNer
Join Date: Jul 2001
Location: S.P.Q.R.
Status: Offline
Reply With Quote
Feb 20, 2006, 10:37 AM
 
Thank you for the instruction. Well, I decided to not use the "delete" function as it scares me. So, I took it out. Problem is that I get an error that says:

Syntax Error
Can't get "write-ups" of folder "crap" of folder "exp" of folder "desktop" of folder "trado" of folder "users" of startup disk. Access not allowed.

Here's the code...

to suckDownFiles(remoteLocation, localLocation)
tell application "Finder"
duplicate every file of remoteLocation to localLocation
select every file of remoteLocation

end tell
end suckDownFiles


set desk to path to desktop as alias
tell application "Finder"
set theiDisk to last disk whose format is WebDAV format


--Writeups
set iDiskFolder to folder "VIII.Write-ups" of folder "ALLEN" of folder "*** Law ***" of folder "Public" of theiDisk
set localFolder to "Write-ups" of folder "Crap" of folder "exp" of folder "Desktop" of folder "trado" of folder "users" of startup disk
my suckDownFiles(iDiskFolder, localFolder)



--Bill of Particulars
set iDiskFolder to folder "II. Bill of Particulars" of folder "ALLEN" of folder "*** Law ***" of folder "Public" of theiDisk
set localFolder to "BPs" of folder "Crap" of folder "exp" of folder "Desktop" of folder "trado" of folder "users" of startup disk
my suckDownFiles(iDiskFolder, localFolder)

--you can repeat this for as many folders as you want....

end tell

     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 20, 2006, 11:01 AM
 
The error there is that you missed out an instance of the word 'folder':

Code:
set foo to "write-ups" of folder "crap"
- means get a property (called "write-ups") of the folder.

what you need is:

Code:
set foo to folder "write-ups" of folder "crap"
- which means get the folder of the folder.

Hope that makes sense.
     
Dedicated MacNNer
Join Date: Jul 2001
Location: S.P.Q.R.
Status: Offline
Reply With Quote
Feb 20, 2006, 11:24 AM
 
Ahhh, got it. Sorry about that. I fixed it, but I am now getting:

Finder got an error: Can't set folder "VIII.Write-ups" of folder "crap" of folder "Exp" of folder "Desktop" of folder "trado" of folder "Users" of startup disk to every file of folder "VIII.Write-ups" of folder "ALLEN" of folder "*** Law ***" of folder "Public" of item "[.MacUserName]".

Does this have something to do with the fact that I have iDisk syncing tunred "on" and therefore my iDisk is ALWAYS on my desktop? I'm a little confused how it found my .Mac User Name when I never set that in the code.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Feb 20, 2006, 11:44 AM
 
The .macusername is the name of the idisk volume - it gets that from the line:
Code:
set theiDisk to last disk whose format is WebDAV format
I'm not sure what's happened to cause that error - that error message says "can't set (a reference to a folder) to (every file of another folder)"

You seem to somehow be trying to set a folder to the contents of another - did you alter the "duplicate" command to "copy"? or something? Did you make other changes to the script?
     
Dedicated MacNNer
Join Date: Jul 2001
Location: S.P.Q.R.
Status: Offline
Reply With Quote
Feb 20, 2006, 01:06 PM
 
nope. I don't get it. The only thing I did was delete the following 2 lines:

select every file of remoteLocation
move selection to the trash -- since it's a remote disk this will delete them immediately..
{I deleted this because I decided to not have it delete the files from the iDisk}

I just keep getting that error. :\

I've been trying to get something working all day. Now I got this new code which ALMOST works. In fact, it does work - except for the fact that it throws an error if any document has "already" been duplicated to my HD. In addition, it won't copy anything that is put in a SUB-subfolder.

One thing good about it tho is that it seemingly requires a LOT less writing. However, I don't know if there are any problems/risks that I should be aware of with it...
If not, is there a way to tweak the code to make it:

(1) just skip/ignore any files that have already been copied to my HD (...or give me a prompt to keep the new one, keep the old one, or keep both); and

(2) copy any new "sub-subfolder" and their contents that my assitant might create in any of the 4 subfolders on the iDisk.

Code:
set my_subfolders to {"II. Bill of Particulars", "III. Correspondence", "IV. Disc/Stips/Misc", "VIII.Write-ups"} --these are the 4 subfolders on the iDisk..each of the 35 Main Folders has these 4 subfolders.. set ThisFolder_iDisk to alias "iDisk:Public:*** Law ***:" set ThisFolder_home to alias "HD:Users:trado:Desktop:Exp:" tell application "Finder" set theseFolders to folders of ThisFolder_iDisk --35 Main Folders.. repeat with i in theseFolders --ALLEN, ANDRADE,etc.. up to 35 set this_name to name of i repeat with k in my_subfolders set fold_path to folder k of i duplicate files of fold_path to folder k of folder this_name of ThisFolder_home end repeat end repeat end tell
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:16 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2