Friday, December 15, 2017

#1 2000-06-05 01:09:05 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Help Modifying Script

I'm trying to modify Apple's 'Synchronize Folders' script so it will automatically synch to files without presenting the 'Choose File' dialogue. I thought I could do this fairly easily by inserting the actual folder names (Folder A, Folder B) and removing the 'Choose' segment.

However I keep getting an error at the duplicate alias stage. Any help appreciated.Script follows:

Applescript:

on run
tell application "Finder"
activate
try
set folder1 to choose folder with prompt "Select the first folder:"
on error -- e.g. user cancelled
return
end try
try
set folder2 to choose folder with prompt "Select the second folder:"
on error -- e.g. user cancelled
return
end try
SyncFolders(folder1, folder2) of me
end tell
end run
on open x
tell application "Finder"
set ErrorString to "Syncronization process needs 2 folders. " & ¬"Please try again with 2 folders."i
f (count items in x) * 2 then
display dialog ErrorString buttons "OK" default button 1
return
end if
set y to item 1 of x
if last character of (y as text) is ":" then --it's a folder
set x to item 2 of x
if last character of (x as text) is ":" then --it's a folder
SyncFolders(x, y) of me
else
display dialog ErrorString buttons "OK" default button 1
end if
else
display dialog ErrorString buttons "OK" default button 1
end if
end tell
end open
on SyncFolders(folder1, folder2)SyncEm(folder1, folder2)SyncEm(folder2, folder1)
end SyncFolders
on SyncEm(folder1, folder2)
tell application "Finder"
set Folder1Contents to list folder folder1
set Folder2Contents to list folder folder2
repeat with x in Folder1Contents
if x is not in Folder2Contents then
duplicate alias ((folder1 as text) & x) to folder folder2
elsei
f kind of alias ((folder1 as text) & x) is "folder" then
SyncFolders(((folder1 as text) & x) as alias, ((folder2 as text) & x) as alias) of me
else
set date1 to modification date of alias ((folder1 as text) & x)
set date2 to modification date of alias ((folder2 as text) & x)
if date1 > date2 then
duplicate alias ((folder1 as text) & x) to folder folder2 with replacing
end if
end if
end if
end repeat
end tell
end SyncEm


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#2 2000-06-06 08:37:16 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Help Modifying Script

The call to the subroutine:

Applescript:

on SyncFolders(folder1, folder2)
SyncEm(folder1, folder2)
SyncEm(folder2, folder1)
end SyncFolders

needs the path names (not names) of two folders; e.g., not my SyncFolder ("Folder A", "Folder B") but the fully-qualified path names:

Applescript:

SyncFolder ("HD:Folders:Folder A","HD:Folders:Folder A")

which must exist, so watch for typos.
macguy


One mans trash is another mans treasure

Offline

 

#3 2000-06-06 10:03:02 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Help Modifying Script

You could use the script as a droplet and drop 2 files
(instead of folders) on it.. but you'd have to copy
the lines concerning the modification dates, into the
on open x function.. for example

Applescript:

on open x
..snipped..
if last character of (y as text) is ":" then --it's a folder
set x to item 2 of x
if last character of (x as text) is ":" then --it's a folder
SyncFolders(x, y) of me
else
display dialog ErrorMessage
end if
else
--assume both are files...relace the errorMessage stuff..
set date1 to modification date of info for alias (y)
set x to item 2 of x
set date2 to modification date of info for alias (x)
if date1 > date2 then
duplicate alias (y) to alias (x) with replacing
...snipped..

Ed


One mans trash is another mans treasure

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)