organisable file catalog which applies changes to original files in different locations

57 views Asked by At

Is there a solution for having

One unified list/catalog of all files and folders from different external harddrives, which can be used to move and rename items but later when that external drive is connected, The relative files/folders get renamed, copied, moved and removed based on changes made in that catalog.

This is because it is very hard and cumbersome to connect all external HDDs and even if connected all of them have to run for the entire duration of organising every file in all drives.

Basically like an Adobe Lightroom Catalog but for files and folders. We can work on the catalog and changes get applied to originals when HDD is connected.

1

There are 1 answers

2
Teja On

Never mind stackoverflow, after three days of rigorous search I found the solution to get what I needed done.

With this process anyone can have only the links of all their Terabytes of files in all their Hard-drives, servers, NASs, Cloud etc. in a small ready to access package (hardly MBs) and can be organised, tagged, renamed and cleaned.

Then later once done can replace all the links with original files in their respective organised and modified locations without any hassle and Hard-drive runtime or strain.

I used apple script to tell finder to do the following, but the arriving at the solution took several twists, turns and trial and errors due to my lack of programming fundamentals and how file systems work.

SOLUTION:

Three steps of apple script to

  1. Replicate a directory structure between a source and destination folder with only folders and sub-folders (all). But with the symbolic links of files rather than the files itself.

  2. Converting all the symbolic links to Mac finder type aliases so that they can be processed with apple script.

  3. Replacing all the aliases with the the original files they are pointing to.

The script for each step is also posted with detailed comments along with the screenshots

STEP 0

STEP 1:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* To prompt a window with to choose source folder *)
set destinationFolder to choose folder with prompt "Choose Destination Folder"
(* To prompt a window with the title choose destination folder *)
tell application "Finder"

    do shell script "/opt/X11/bin/lndir " & quoted form of POSIX path of sourceFolder & " " & quoted form of POSIX path of destinationFolder & ""
    (* Using shell to execute "lndir" command with its path (as there was a 'command not found' error initially)
        and since we need to use HFS style paths of source and destination directories in the lndir command,
        we are using the quoted form of HFS path i.e. POSIX style (because apple script's POSIX style paths of sourceFolder
        and destinationFolder references used in the beginning lines of script are not used in shell *)

end tell


(* Installing lndir command to terminal is step 1 and it is downloaded using go from github (https://github.com/launchdarkly/go-lndir) *)

(* lndir command whihc is a unix command replicates the directory strucutre of folders and sub-folders between source and destination folders
excluding the files but places the symbolic links of the files instead in the destination directories *)

(* unix lndir man page (http://www.xfree86.org/4.3.0/lndir.1.html) *)

STEP 1

STEP 2:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* get a prompt windows to choose source folder *)

tell application "Finder"
    set allSymLinks to entire contents of sourceFolder
    (* define a variable allSymlinks so that every file in that folder is scanned for its kind and arrayed *)
    repeat with aSymLink in allSymLinks
        (* repeat the following for every file found (as a variable 'aSymLink') in the array made ('allSymLinks')*)
        if kind of aSymLink is alias then
            (* if the file type is an alias (which is the same for both symbolic link and a mac finder alias) then *)
            set posixPath to POSIX path of aSymLink
            (* set variable to the POSIX path of that file (as it is required for apple script) *)
            move aSymLink to trash
            (* move that symbolic link file to trash *)
            set aliasPath to POSIX file of posixPath as alias
            (* set a variable 'aliasPath' while making a POSIX file (a mac finder alias file)
            with the POSIX path acquired from the symbolic link before we moved it to trash *)
        end if
    end repeat
end tell

(* this script is an intermediary step only because the apple script would't work when we simply write the 'if' condition with kind is alias then...
as though the kind of Symbolic Link is alias, for some reason apple script didn't use it as it would with an original mac finder alias,
so we are converitng it to mac finder type alias using the POSIX path*)

(* Probably the reason might be that apple script can only fetch the original file if the path is of POSIX style *)

STEP 2

STEP 3:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* get a prompt windows to choose source folder *)

tell application "Finder"
    set allAliases to entire contents of sourceFolder
    (* define a variable allAliases so that every file in that folder is scanned for its kind and arrayed *)
    repeat with anAlias in allAliases
        (* repeat the following for every file found (as a varaible 'anAlias') in the array made ('allAliases')*)
        if class of anAlias is alias file then
            (* if the file's class type is an alias then *)
            set originalFile to original item of anAlias
            (* defining originalFile to the original file the alias is pointing to *)
            set containerFolder to container of anAlias
            (* defining contianerFolder to the folder the alias is pointing to *)
            move anAlias to trash
            (* deleting the alias to trash *)
            move originalFile to containerFolder
            (* moving the original file to the folder *)
        end if
    end repeat
end tell

(* Apple Script didn't work when like in the previous step's script If i wrote 'kind is alias', before I changed them to POSIX style alias,
which apple script seems to work with *)

(* Probably the reason might be that apple script can only fetch the original file if the path is of POSIX style *)

STEP 3_a

STEP 3_b.

I wished there was an app for all this

But then I would have never learned all these.

Hoping this will be useful to everyone in need.

Good Day