Dateiliste in Numbers führen an Hand von Dateinamen

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

Leave a Reply