PDA

View Full Version : folder structure as database


pieman1968
08-15-2010, 07:17 PM
Been trying to organise a database of equipment we have but organising this into case and kits/jobs is a pain in most database systems, Mysql etc. So I thought perhaps using the finder might be a way.

Basically each "equipment" item is a folder, each piece of "equipment" is stored for transport in a "case"
Each "case" is a folder
Each "Kit" folder contains a number of "case" folders containing a number of "equipment" folder items.
The information necessary for the database is stored in the folder name and spotlight comments

eg

Kit/

case 1/
camera1
sound kit1

case 2/
camera2
soundkit2

I need to write a script that will look at the root folder Kit and then list all the folders into a file in a way that they can then be opened in openoffice as a CSV file and create a spreadsheet.

What I like about this approach is custom images can be added to the folders. Users can drag/copy items into "case" folders very easily without dealing with a database

The Spotlight comments could hold additional "," delimited info such as serial number, country of origin, value.

I have been testing a script I found on the net with text wrangler but perhaps it is the wrong approach

---------
tell application "Finder"
set selec to selection as alias
set conta to container of selec as alias

set item_Name to name of selec
end tell
tell application "TextWrangler"
activate

open conta
end tell


tell application "System Events"
tell process "TextWrangler"

end tell
end tell



tell application "Finder"
set selec to selection as alias

set conta to POSIX path of selec

end tell
tell application "TextWrangler"
activate
make new text document
tell application "System Events"
tell process "TextWrangler"
click menu item "Folder Listing…" of menu 1 of menu item ¬
"Insert" of menu 1 of menu bar item "Edit" of menu bar 1
keystroke "g" using {command down, shift down}
keystroke conta
repeat 2 times
keystroke return
end repeat

end tell
end tell

end tell
-------------
This looks like it could work. But I can't work out how to control the print out to the file or add the Spotlight comments fields. So they are a proper CSV format

Any ideas.

Cheers

renaultssoftware
08-16-2010, 08:26 AM
To print, it's easy to use the print the front document command. In the Finder, you can set a file's comments like this:
tell application "Finder" to set the comment of randomFile to "Dead frogs"

Hans-Gerd Claßen
08-29-2010, 07:07 AM
Hi piemann1968,

hope i got you right ;-)

try this:
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""

set FolderSet to ""
set ThisFolder to choose folder
tell application "Finder"
set routeFolder to name of folder ThisFolder
set xFolder to name of folders of folder ThisFolder
end tell

repeat with i from 1 to count of xFolder
set tmpStrg to ""
set caseFolder to item i of xFolder
set AliasFolder to ((ThisFolder as text) & caseFolder & ":") as alias
set AComment to my readComment(AliasFolder)
set tmpStrg to ";" & caseFolder & " Spotlight Comment: " & AComment
tell application "Finder"
set SubCaseFolders to name of folders of folder ((ThisFolder as string) & caseFolder)
set tmpList to {}
repeat with f from 1 to count of SubCaseFolders
set ThisSubFolder to item f of SubCaseFolders
set AliasFolder to ((ThisFolder as text) & caseFolder & ":" & ThisSubFolder & ":") as alias
set AComment to my readComment(AliasFolder)
set tmpStrg2 to ";" & ThisSubFolder & " Spotlight Comment: " & AComment
set end of tmpList to tmpStrg2
end repeat

set AppleScript's text item delimiters to return & ";"
set tmpStrg to tmpStrg & (tmpList as text) & return
set AppleScript's text item delimiters to ""

end tell
set FolderSet to FolderSet & tmpStrg
end repeat

set FolderSet to routeFolder & FolderSet

set ThisFile to ((path to desktop) & "Mein.csv" as Unicode text)

my write_to_file(FolderSet, ThisFile, false)
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file as «class utf8» starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file

set AppleScript's text item delimiters to tid

on readComment(aFolderAlias)
tell application "Finder"
set AComment to comment of aFolderAlias
return AComment
end tell

end readComment


Output should be a File Mein.csv on your desktop

struktured like this:

kit;case1 Spotlight Comment: Kommentar Nr. 1;camera1 Spotlight Comment: Hier steht was
;;sound1 Spotlight Comment:
;case2 Spotlight Comment: klklkmkl;sound2 Spotlight Comment:
;;sound2 Kopie 1 Spotlight Comment:
;;sound2 Kopie 2 Spotlight Comment:
;;sound2 Kopie 3 Spotlight Comment:
;;sound2 Kopie 4 Spotlight Comment:

Greets

Hans