Ordneraktion: Verschiebe Datein aus Ordner A in Ordner C der in Ordner B erstellt wird…?!

16/10/2010
Ja ehm... die Überschrift trifft es ziemlich genau, mehr Worte (z.B. Ordner) würden nur verwirren =)
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--Ordner-Aktion die alle betroffenen Dateien in einen anderen (neu erstellten Ordner

-- verschiebt, dessen Name vorher abgefragt wird.

-- dieser neue Ordner wird wiederum in einem anderen Ordner erstellt, von dem sich ein Alias

-- in dem Ordner der Ordner-Aktion befindet.

-- Befindet sich bereits eine Datei mit dem gleichen Namen im Zielverzeichnis,

-- wird diese NICHT überschrieben, sondern die neue Datei wird entsprechend umbenannt (durchnummeriert).


-- ehm, um wieviele verschiedene Ordner geht es hier eigentlich?


on adding folder items to this_folder after receiving these_items

try

tell application "Finder"

set folderkind to kind of folder 1 of startup disk

set aliascount to count of every alias file of (this_folder as reference)

--wenn der Alias des Zielordners vorhanden ist kann es weitergehen

if aliascount is 1 then

set destination_folder to (original item of alias file 1 of (this_folder as reference))

set destination_folder_posix to POSIX path of (destination_folder as alias)

--ist der Zielordner auch ein Ordner oder eine Datei? Dann Fehler!

if kind of destination_folder is not folderkind then

error "Hm, der Zielordner ist gar kein Ordner..."

end if

--Ordnernamen abfragen, der im Zielordner angelegt werden soll

set foldername to text returned of (display dialog "Bitte die Ausgabe und das Jahr angeben:" buttons {"Ok"} default button "Ok" default answer "Woche-Jahr")

-- den Ordner anlegen

do shell script "mkdir -p " & quoted form of (destination_folder_posix & foldername)

-- und jetzt jede Datei in den neu angelegten Zielordner bewegen, dabei aber auf doppelte Dateinamen achten und ggf. umbenennen

repeat with this_item in these_items

set item_name to name of this_item

set this_item_posix to POSIX path of (this_item as reference)

set uniq_name to my checkname_with_pdf_suffix(item_name, folder foldername of destination_folder, false)

do shell script "mv " & quoted form of this_item_posix & " " & quoted form of (destination_folder_posix & foldername & "/" & uniq_name)

end repeat

else

error "Zielalias nicht vorhanden oder es gibt mehr als einen Alias..."

end if

end tell

on error msg

display dialog msg

end try

end adding folder items to



to checkname_with_pdf_suffix(n, D, looped)

--check if filename exists in D

-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

No Comments

Finder: Move biggest file of folders to first folder

16/04/2010
Ein paar Ordner auswählen und die jeweils größte Datei wird in den ersten Ordner bewegt... Ich kann es gebrauchen, sag' aber nicht weshalb ;-P
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

tell application "Finder"

set these to selection

set folderkind to kind of folder 1 of startup disk

set movetothisfolder to ""

repeat with this in these

if kind of this is folderkind then

if movetothisfolder = "" then

set movetothisfolder to this

end if

set these2 to every item of this

set biggestsize to 0

repeat with this2 in these2

if size of this2 > biggestsize then

set biggestsize to size of this2

set movethis2 to this2

end if

end repeat

move movethis2 to movetothisfolder

end if

end repeat

end tell

No Comments

AppleScript: Bild-Datein und PDFs weg sortieren…

19/03/2010
Erst mal Danke an rumbleinthedesert für die Spende, für das Skript! Damit lassen sich PDFs (und nunmehr auch Bilder) einfach sichten und weg sortieren. Man hat einen Ordner mit seinen Bildern, in diesem Ordner sind vielleicht schon mögliche Zielordner enthalten, ansonsten kann man im Verlauf des Skriptes auch neue Ordner anlegen lassen...
Zieht man nun diesen Ordner auf das unten gezeigte, als AppleScript-Programm gespeicherte Skript, öffnet es der Reihe nach die Bilder oder PDFs in der Vorschau, zeigt einem eine Liste der Zielordner an und man kann recht flott die Bilder weg sortieren. Ist dem Mail-Skript nicht unähnlich....
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on open thefolder

if (count of thefolder) = 1 then

tell application "Finder"

set thefolder to (item 1 of thefolder) as alias

set thefolder_posix to POSIX path of (thefolder as alias)

set sort_destis to name of every folder of thefolder

set thepdfs to every file of thefolder

repeat with thepdf in thepdfs

if name of thepdf ends with ".pdf" or name of thepdf ends with ".png" or name of thepdf ends with ".jpg" or name of thepdf ends with ".gif" or name of thepdf ends with ".psd" then

set thepdf_posix to POSIX path of (thepdf as alias)

do shell script "open -a /Applications/Preview.app " & quoted form of thepdf_posix

tell me to activate

tell me to set thedesti to choose from list {"••NEW Folder••"} & sort_destis with prompt "In welchen Ordner verschieben?"

if thedesti as text = "••NEW Folder••" then

set newfoldername to ""

repeat until newfoldername ≠ ""

tell me to set newfoldername to text returned of (display dialog "Name of new Folder" default answer "")

try

do shell script "cd " & quoted form of thefolder_posix & ";mkdir " & quoted form of newfoldername

end try

set thedesti to newfoldername

end repeat

end if

tell application "Preview"

activate

--kleiner Pfusch, weil die Vorschau keine AppleScript-Befehle kennt...

tell application "System Events"

keystroke "w" using command down

end tell

end tell

do shell script "mv " & quoted form of thepdf_posix & " '" & thefolder_posix & thedesti & "/" & my checkname_with_pdf_suffix(name of thepdf, ((thefolder & thedesti) as text) as alias, false) & "'"

end if

end repeat

end tell

tell me to activate

tell me to display dialog "bin am Ende"

end if

end open


on checkname_with_pdf_suffix(n, D, looped)

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

No Comments

Maus Zeiger in AppleScript via Python bewegen

18/09/2009
Von hinten durch AppleScript, via Python in das Cocoa-Framework ;-)
Code zum markieren einmal anklicken oder Code im Skript-Editor öffnen

do shell script "python -c \"import objc;bndl = objc.loadBundle('CoreGraphics', globals(), '/System/Library/Frameworks/ApplicationServices.framework');objc.loadBundleFunctions(bndl, globals(), [('CGWarpMouseCursorPosition', 'v{CGPoint=ff}')]);CGWarpMouseCursorPosition((0, 0));\""

Eine alltagstaugliche Alternative findest Du hier.
8 Comments

Mal flink Dateien im Finder verschieben

5/09/2009

Ich sortiere gerade meine zig Dateien und Ordner, die ich in den letzten Monaten angelegt habe. Ein Bild hier, ein nettes Tool dort... und hey, diesen Text wollte ich noch lesen.
Ich bezweifle, dass ich alles von dem Zeug noch brauchen werde, aber um wenigstens die paar Dinge wieder zu finden und halbwegs geordnet abzulegen, habe ich mir ein kleines Skript geschrieben,

mit dem ich die Auswahl im Finder in einen beliebigen Unterordner verschieben kann. Ggf. kann ich den auch noch darüber erstellen.

Das Ding habe ich mir jetzt über FastScripts auf einen Short-Cut gelegt und flux ist der der Finder um das Feature -> Bewege Auswahl in Unterordner XY reicher =)

Code zum markieren einmal anklicken oder Code im Skript-Editor öffnen

--hubionmac.com 05.09.2009

tell application "Finder"

set myfolder to container of ((item 1 of (selection as list)) as alias)

set folderlist to (name of every container of myfolder)

end tell

set selectionNames to getSelectionNames()

set folderlist to BubbleSort(folderlist)

set folderlist to {"----NewFolder----"} & CheckupLists(folderlist, selectionNames)

tell application "Finder"

set theaction to choose from list folderlist default items {item 1 of folderlist}

if theactionfalse then

if theaction as text = (item 1 of folderlist) as text then

set foldername to text returned of (display dialog "New folder name?" default answer "new folder")

set thefolder to make new folder at myfolder with properties {name:foldername}

move selection to thefolder

else

move selection to folder (theaction as text) of myfolder

end if

end if

end tell

on BubbleSort(theList)

if class of theList is list then

set theSize to length of theList

repeat with i from 1 to theSize

repeat with j from 2 to (theSize - i + 1)

if ((item (j - 1) of theList) > (item j of theList)) then

set temp to (item (j - 1) of theList)

set (item (j - 1) of theList) to (item j of theList)

set (item j of theList) to temp

end if

end repeat

end repeat

return theList

else

return false

end if

end BubbleSort

on getSelectionNames()

tell application "Finder"

set b to {}

repeat with a in (selection as list)

set b to b & name of a

end repeat

end tell

return b

end getSelectionNames

on CheckupLists(folderlist, selectionNames)

set ff to {}

repeat with f in folderlist

if selectionNames does not contain f then

set ff to ff & f

end if

end repeat

return ff

end CheckupLists

No Comments