Dateiliste in Numbers führen an Hand von Dateinamen

14/09/2011
Ich habe z.B. in Numbers eine Liste mit allen Job-IDs und möchte in einer Spalte daneben alle Dateien aus einem Bestimmten Verzeichnis auflisten, deren Name diese Job-ID beinhaltet... nix leichter als das:

--14.09.2011 hubionmac.com

-- parts of numbers selection code by http://hints.macworld.com/article.php?story=20090109055630154

-- requested @https://discussions.apple.com/thread/3325583?tstart=0

-- this script takes the value of a selection in numbers first and a asks for a folder

-- then the values of the first column of the selection are taken and all filenames of start start with that folder and are found in the defined folder will be

-- writen to the last column of the selection ----> you will have to select at least 2 columns


set thefolder to quoted form of POSIX path of ((choose folder) as alias)


tell application "Numbers"

activate

tell document 1

-- DETERMINE THE CURRENT SHEET

set current_sheet_index to 0

repeat with i from 1 to the count of sheets

tell sheet i

set x to the count of (tables whose selection range is not missing value)

end tell

if x is not 0 then

set the current_sheet_index to i

exit repeat

end if

end repeat

if the current_sheet_index is 0 then error "No sheet has a selected table."

-- GET THE VALUES OF THE SELECTED CELLS

tell sheet current_sheet_index

set the current_table to the first table whose selection range is not missing value

tell the current_table

set range_column_count to count of every column of selection range

set this_rows_first_cell_index to 1

set this_rows_last_cell_index to range_column_count

-- THIS CHANGES THE VALUE OF 

repeat with i from 2 to count of every cell of selection range

set thename to value of cell this_rows_first_cell_index of selection range

set foundfilenames to my find_filenames(thefolder, thename)

set value of cell this_rows_last_cell_index of selection range to foundfilenames

set this_rows_first_cell_index to this_rows_first_cell_index + range_column_count

set this_rows_last_cell_index to this_rows_last_cell_index + range_column_count

if this_rows_last_cell_index > (count of every cell of selection range) then exit repeat

end repeat

end tell

end tell

end tell

end tell



on find_filenames(thefolder, filename_start)

-- THIS SEARCHES FILES STARTING WITH A SPECIFIC STRING IN THEIR NAMES AND OUTPUTS JUST THEIR FILENAMES

-- IS SEARCHES IN THEFOLDER AND ALL SUB-DIRECTORIES

set theoutput to do shell script "cd " & thefolder & ";find " & "." & " -iname \"" & filename_start & "*\""

if theoutput ≠ "" then

set theoutput to every paragraph of theoutput

--OPTIONAL REMOVE THE FIRST CHARACTER OF EACH PATH

set tmp to {}

repeat with t in theoutput

set tmp to tmp & {(characters 2 through -1 of t) as text}

end repeat

set theoutput to tmp

set AppleScript's text item delimiters to "; "

set theoutput to theoutput as text

set AppleScript's text item delimiters to ""

end if

return theoutput

end find_filenames

No Comments

Alias Liste der neuesten Dateien

22/02/2011

Ich habe mal in meiner alten AppleScript-Sammlung etwas gestöbert und bin über ein Skript gestolpert, welches ich vor einer halben Ewigkeit geschrieben haben. Damit lassen sich Ordner auf die neusten Dateien hin durchsuchen und für dieses Dateien werden anschließend erst symbolische Links erstellt. Diese Unix-Links werden dann in OSX Aliase konvertiert und in einen Zielordner bewegt... Schon strange wenn man Quellcode von vor über 6 Jahren findet... und noch ein kleines Handbuch dazu

--hubionmac.com 07.02.2005

--#################################--Preferences--#################################--

property daycount : 4

property depth_scan_switch : "off" --(on/off)

property dirname_in_aliasname : "off" --(on/off)


--###########################################################################--


global maxfolderdeep, folderkind, destination_folder, current_folder_name, tempfolder


--## Set all working directories

tell application "Finder"

set folderkind to kind of folder 1 of startup disk

try

set aliasfolder to (folder "recent_uploads_aliases" of startup disk) as alias

on error

make new folder at startup disk with properties {name:"recent_uploads_aliases"}

set aliasfolder to (folder "recent_uploads_aliases" of startup disk) as alias

--error "A folder called \"recent_uploads_aliases\" has been created at your startup disk."

end try

try

set temp_folder to folder "_temp" of aliasfolder as alias

set tempfolder to POSIX path of temp_folder

on error

make new folder at (aliasfolder as alias) with properties {name:"_temp"}

set temp_folder to folder "_temp" of aliasfolder as alias

set tempfolder to POSIX path of temp_folder

end try

set scan_group_folders to every folder of (aliasfolder as alias)

end tell


--## Now scan every folder

repeat with current_scan_group_folder in scan_group_folders

tell application "Finder" to set itemname to name of current_scan_group_folder

if itemname as text ≠ "_temp" then

--## clean the tempdir and the destination folder from aliases and links

tell application "Finder" to set destination_folder to original item of alias file "destination_folder" of current_scan_group_folder

do shell script "rm -f " & quoted form of (POSIX path of (destination_folder as alias)) & "*"

do shell script "rm -f " & quoted form of tempfolder & "*"

tell application "Finder" to set the_folders to every alias file of current_scan_group_folder

repeat with the_folder in the_folders

if name of the_folder ≠ "destination_folder" then

tell application "Finder" to set thepath to original item of the_folder

if depth_scan_switch = "on" then

set maxfolderdeep to (character 1 of ((name of the_folder) as text)) as integer

else

set maxfolderdeep to 1

end if

tell application "Finder" to set thefolder to original item of (the_folder as alias)

set current_folder_name to (name of thefolder) as text

make_sym_links(thepath)

end if

end repeat

-- ## create aliases of symbolic links at the destination directory

tell application "Finder"

set these_ to every item of temp_folder

repeat with this_ in these_

if dirname_in_aliasname = "on" then

set name_01 to name of container of (original item of this_)

set name_00 to name of (original item of this_)

set aliasname to name_00 & " @ " & name_01 as string

make new alias file to ((original item of this_) as alias) with properties {name:aliasname} at destination_folder

else

make new alias file to ((original item of this_) as alias) at destination_folder

end if

end repeat

end tell

end if

end repeat



on make_sym_links(the_folder)

set thepath to POSIX path of (the_folder as alias)

do shell script "find " & quoted form of thepath & " -ctime -" & daycount & " -maxdepth " & maxfolderdeep & " -mindepth " & maxfolderdeep & " -exec ln -s {} " & quoted form of tempfolder & " \\;"

end make_sym_links

4 Comments

Apple Mail: EMLX-Datei der ausgewählte Nachricht speichern

29/12/2010
Apple Mail nutzt glaube ich seit Leopard nicht mehr eine fette mbox Datei sondern einzelne .emlx Dateien zum speichern der abgerufenen Emails. So können die Dateien schön einzeln indiziert (Spotlight) werden und können auch recht leicht kopiert werden (TimeMachine). Eine solche EMLX-Datei lässt sich über Quicklook oder Apple Mail betrachten und beinhaltet sogar die in der Email enthaltenen Anhänge.
Dummerweise kann man via AppleScript nicht direkt den Speicherort der Email abfragen, aber da die emlx-Datei nach der ID der Email benannt ist, kann man sie recht leicht im entsprechenden Account-Ordner finden. Das tut dieses Skript also, es sucht sich die emlx-Dateien der ausgewählten Emails kopiert diese auf den Schreibtisch...
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--hubionmac.com 29.12.2010 EMLX-Dateien ausgewählter Emails in einen Order (Saved_Mails(Acountname) auf dem Schreibtisch kopieren... (4 Chris_Zuerich)


--auswahl aus Apple Mail abfragen

set mymails to my getSelection()

repeat with mymail in mymails

tell application "Mail"

--das Verzeichnis des Email Accounts ausfindig machen

set accountDir to quoted form of POSIX path of ((account directory of account of mailbox of mymail) as alias)

set account_name to (name of account of mailbox of mymail) as text

tell application "Finder" to set temp_dir to quoted form of (POSIX path of (desktop as alias) & "Saved_Mails (" & account_name & ")/")

try

do shell script "mkdir " & temp_dir

end try

--in dem Account-Verzeichnis nach der der Email-Datei suchen und diese kopieren...

set myid to id of mymail

do shell script "find " & accountDir & " -name " & myid & "*.emlx* -exec cp {} " & temp_dir & " \\;"

end tell

end repeat


on getSelection()

tell application "Mail"

set a to selection

if (count of a) < 1 then

error "Eine Mitteilung muss ausgewählt sein."

end if

return a

end tell

end getSelection

Ein Grund für den regen Gebrauch von Wildcards im find-Befehl ist die Tatsache, dass besonder große Emails aufgesplittet werden in .emlx und .emlxpart Dateien. Gemeinsamer Nenner ist aber immer die ID, mit der der Dateiname stets beginnt.
No Comments

iTunes Media Server .song.mp3

25/05/2008
Ich habe er glaube ich schon einmal erwähnt. Der iTunes Server von Synology ist zwar letztendlich von der Geschwindkeit in Ordnung, doch hat er eben auch einige Macken. So legt der Mac beim Kopieren bzw. bearbeiten von Dateien noch eine Datei mit dem gleichen Namen, nur mit . davor, in gleichen Verzeichnis an. Der iTunes Server glaubt nun, dass es sich auch um eine mp3-Datei handelt und indiziert sie. Da ich mir diesen Nerv-Faktor beim neuen NAS ersparen wollte habe ich vor dem Indizieren des music-Ordners noch über einen Terminal-Befehl alle Dateien mit einem . am Anfang gesucht unddiese gelöscht. Da das find auf dem Synology-NAS wohl den -exec Befehl nicht (von -delete mal gar nicht angefangen) unterstützt habe ich das Share einfach über smb am Mac gemountet und das OSX-find bemüht.
Die Zeile zur Erinnerung =): cd /volumes/music/ das solle das gemountet share sein, also das Arbeitsverzeichnis und dann find ./ -name ".*" -delete jetzt geht es den Dateien an den Kragendirekt auf dem nas kann man zwischenzeitlich mal überprüfen wieviele Dateien er noch zu löschen hat find /volume1/music/ -name ".*" | wc -l
No Comments