Frage zu Applescript (Ordneraktion)

D

da_FloZinger

Registriert
Thread Starter
Dabei seit
13.09.2015
Beiträge
2
Reaktionspunkte
0
Hallo zusammen,

ich bin relativ neu mit Applescript und habe mir aus ein paar Codeschnipseln im Netz eine kleine Ordneraktion zum Import von gescannten Dateien in Evernote zusammengebastelt.

Das Script läuft bis zum umbenennen der Datei, dannach passiert leider nix mehr.

Vielleicht könnte mir jemand von euch unter die Arme greifen?!

Danke schonmal
Gruß
FloZi


property theDelims : {","}
property delete_Files : "ON"
property EVnotebook : ""
property EVTag : {}

on adding folder items to thisFolder after receiving itemList
repeat with aFile in itemList
set fullPath to (aFile as string)


tell application "Preview"
open aFile
end tell


-- EINSTELLUNGEN
set scripttitle_ to "FloZis Evernote Importer Script - V2.3"
set tagging_Switch to "ON"




-- ABFRAGE - BELEGDATEN
display dialog "Datum eingeben:" & return & "(Format: YYYY-MM-DD)" with title scripttitle_ default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon note
set Belegdatum_ to text returned of the result

display dialog "Firma/Austeller eingeben:" & return & "(z.B. Apple)" with title scripttitle_ default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon note
set Belegfirma_ to text returned of the result

display dialog "Belegtitel/Bezeichnung eingeben:" & return & "(z.B. Rechnung)" with title scripttitle_ default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon note
set Belegtitel_ to text returned of the result

display dialog "Bezeichnung eingeben:" & return & "(z.B. iPad)" with title scripttitle_ default answer "" buttons {"OK", "Abbrechen"} default button 1 with icon note
set Belegbezeichnung_ to text returned of the result

set Titel_ to Belegdatum_ & "_" & Belegfirma_ & "_" & Belegtitel_ & "-" & Belegbezeichnung_

tell application "Preview"
quit
end tell

tell application "Finder"
set the name of aFile to Titel_ & ".pdf"
end tell
end repeat
delay 1
------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------

tell application "Evernote"

-- TAGGING AND NOTEBOOK SELECTION DIALOG (DEFAULT IS ON)

if tagging_Switch is "ON" then my tagging_Dialog()

-- MAKE THE NOTE IN EVERNOTE

-- IF TAGS ARE EMPTY…
if EVTag is {} then
-- IF NOTEBOOK IS EMPTY…
if EVnotebook is "" then
create note from file aFile
else
create note from file aFile notebook EVnotebook
end if
else
-- IF TAGS EXIST…
-- IF NOTEBOOK IS EMPTY…
if EVnotebook is "" then
set new_Note to create note from file aFile
assign EVTag to new_Note
else
set new_Note to create note from file aFile notebook EVnotebook
assign EVTag to new_Note
end if
end if

-- SILENT DELETE OF FILE
if delete_Files is "ON" then
set trash_Folder to path to trash folder from user domain
do shell script "mv " & quoted form of POSIX path of aFile & space & quoted form of POSIX path of trash_Folder
end if


--RESET NOTEBOOK
set EVnotebook to ""
end tell


------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------

end adding folder items to



(*
======================================
// EVERNOTE SUBROUTINES
======================================
*)

--TAGGING AND NOTEBOOK SELECTION DIALOG
on tagging_Dialog()
try
display dialog "" & ¬
"Bitte TAGs eingeben (oder mit ENTER übernehmen):
(Mehrere durch Komma trennen)" with title scripttitle_ default answer Belegfirma_ & ", " & Belegtitel_ & ", " & Belegbezeichung_ buttons {"Im Standardnotizbuch erstellen", "Notizbuch auswählen...", "Cancel"} default button "Im Standardnotizbuch erstellen" cancel button ¬
"Cancel" with icon path to resource "Evernote.icns" in bundle (path to application "Evernote")
set dialogresult to the result
set userInput to text returned of dialogresult
set ButtonSel to button returned of dialogresult
set theDelims to {","}
on error number -128
set errNum to -128
end try

--ASSEMBLE LIST OF TAGS
set theTags to my Tag_List(userInput, theDelims)

--RESET, FINAL CHECK, AND FORMATTING OF TAGS
set EVTag to {}
set EVTag to my Tag_Check(theTags)

--SELECT NOTEBOOK
if ButtonSel is "Notizbuch auswählen..." then set EVnotebook to my Notebook_List()
end tagging_Dialog

--GET EVERNOTE'S DEFAULT NOTEBOOK
on default_Notebook()
tell application "Evernote"
set get_defaultNotebook to every notebook whose default is true
if EVnotebook is "" then
set EVnotebook to name of (item 1 of get_defaultNotebook) as text
end if
end tell
end default_Notebook

--TAG SELECTION SUBROUTINE
on Tag_List(userInput, theDelims)
set oldDelims to AppleScript's text item delimiters
set theList to {userInput}
repeat with aDelim in theDelims
set AppleScript's text item delimiters to aDelim
set newList to {}
repeat with anItem in theList

--ADD TAG TO LIST
set newList to newList & text items of anItem
end repeat
set theList to newList
end repeat
set AppleScript's text item delimiters to oldDelims
return theList
end Tag_List

-- CREATES TAGS IF THEY DON'T EXIST
on Tag_Check(theTags)
tell application "Evernote"
set finalTags to {}
repeat with theTag in theTags

-- TRIM LEADING SPACE, IF ANY
if (the character 1 of theTag is " ") then set theTag to text 2 thru end of theTag as text

-- DOES THE TAG ALREADY EXIST?
if (not (tag named theTag exists)) then
try
set makeTag to make tag with properties {name:theTag}
set end of finalTags to makeTag
end try
else
set end of finalTags to tag theTag
end if
end repeat
end tell
return finalTags
end Tag_Check

--EVERNOTE NOTEBOOK SELECTION SUBROUTINE
on Notebook_List()
tell application "Evernote"
activate
set listOfNotebooks to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTEBOOKS *)
set EVNotebooks to every notebook (*GET THE NOTEBOOK LIST *)
repeat with currentNotebook in EVNotebooks
set currentNotebookName to (the name of currentNotebook)
copy currentNotebookName to the end of listOfNotebooks
end repeat
set Folders_sorted to my simple_sort(listOfNotebooks) (*SORT THE LIST *)
set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
"Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook" (*USER SELECTION FROM NOTEBOOK LIST *)
if (SelNotebook is false) then (*CREATE NEW NOTEBOOK OPTION *)
set userInput to ¬
text returned of (display dialog "Enter New Notebook Name:" default answer "")
set EVnotebook to userInput
else
set EVnotebook to item 1 of SelNotebook
end if
end tell
end Notebook_List

(*
======================================
// UTILITY SUBROUTINES
======================================
*)

-- SORT SUBROUTINE
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
 
debuggen kannst du leicht, wenn du an entsprechenden stellen display dialog einbaust.
check vor allem deine EV-vars, evtl. darfst du die nicht als property (wird gespeichert und evtl. kommts nicht zum "reset") definieren.
 
Zurück
Oben Unten