Fischer-Bayern.de
 FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   BenutzergruppenBenutzergruppen   RegistrierenRegistrieren 
 ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin 

Frage zu Applescript (Ordneraktion)

 
Neues Thema eröffnen   Neue Antwort erstellen    Fischer-Bayern.de Foren-Übersicht -> AppleScript X
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
FloZi
•->
•->


Anmeldedatum: 24.06.2016
Beiträge: 2

BeitragVerfasst am: 24.06.2016 - 08:22    Titel: Frage zu Applescript (Ordneraktion) Antworten mit Zitat

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


Code:
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
Cool Rolling Eyes Rolling Eyes
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
FloZi
•->
•->


Anmeldedatum: 24.06.2016
Beiträge: 2

BeitragVerfasst am: 28.06.2016 - 17:47    Titel: Antworten mit Zitat

Hallo nochmal,

ich habs nun etwas umgebaut, habe aber nun das Problem das es nach dem umbenennen der Datei stoppt.


Hier das Script:

Code:
tell application "Finder"
try
set ItemList to selection
repeat with i from 1 to count of ItemList
set thisItem to item i of ItemList

--Datei zum anzeigen öffnen
tell application "Preview"
open thisItem
end tell

--Belegdaten abfragen
display dialog "Belegdatum eingeben:" & return & "(Format: YYYY-MM-DD)" with title "Script by FloZi.de" default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon path to resource "Evernote.icns" in bundle (path to application "Evernote")
set Belegdatum_ to text returned of the result
tell application "Evernote"
activate
set ListOfTags to {}
set allTags to every tag
repeat with currentNotebook in allTags
set currentTagName to (the name of currentNotebook)
copy currentTagName to the end of ListOfTags
end repeat
set Folders_sorted to my simple_sort(ListOfTags)
set SelTag to choose from list of Folders_sorted with title "TAG Auswählen" with prompt ¬
"TAG 1 auswählen (Firma):" OK button name "OK" cancel button name "Abbrechen"
set EVTag1 to item 1 of SelTag
set Belegfirma_ to item 1 of SelTag

set ListOfTags to {}
set allTags to every tag
repeat with currentNotebook in allTags
set currentTagName to (the name of currentNotebook)
copy currentTagName to the end of ListOfTags
end repeat
set Folders_sorted to my simple_sort(ListOfTags)
set SelTag to choose from list of Folders_sorted with title "TAG Auswählen" with prompt ¬
"TAG 2 auswählen (Belegart):" OK button name "OK" cancel button name "Abbrechen"
set EVTag2 to item 1 of SelTag
set Belegart_ to item 1 of SelTag
end tell

display dialog "Bezeichnung eingeben:" & return & "(z.B. iPad)" with title "Script by FloZi.de" default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon path to resource "Evernote.icns" in bundle (path to application "Evernote")
set Belegbezeichnung_ to text returned of the result
set Belegname_ to Belegdatum_ & "_" & EVTag1 & "_" & EVTag2 & "-" & Belegbezeichnung_

-- Datei wieder schliessen
tell application "Preview" to quit

--Datei umbenennen
set name of thisItem to Belegname_ & ".pdf"
set NeueDatei to selection

-- Einstellungen für Evernote import
set Notizbuch to "ABLAGE" -- Notizbuch

-- Nach Evernote importieren
tell application "Evernote"
create note from file NeueDatei notebook {Notizbuch} tags {EVTag1, EVTag2}
end tell
end repeat
end try
end tell


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

-- 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
end simple_sort



Und hier die Events aus AppleScript:
Code:
tell application "Finder"
get selection
open document file "2016-01-01_.TEST_.TEST-TEST.pdf.pdf" of folder "test" of folder "Desktop" of folder "FloZi" of folder "Users" of startup disk
end tell
tell application "Evernote"
path to current application
end tell
tell application "Finder"
path to resource "Evernote.icns" in bundle alias "Macintosh SSD:Applications:Evernote.app:"
display dialog "Belegdatum eingeben:
(Format: YYYY-MM-DD)" with title "Script by FloZi.de" default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon alias "Macintosh SSD:Applications:Evernote.app:Contents:Resources:Evernote.icns"
end tell
tell application "Evernote"
activate
get every tag

get name of tag ".TESTTAG1"
get name of tag "TESTTAG2"

choose from list {".TESTTAG1", "TESTTAG2"} with title "TAG Auswählen" with prompt "TAG 2 auswählen (Belegart):" OK button name "OK" cancel button name "Abbrechen"
path to current application
end tell
tell application "Finder"
path to resource "Evernote.icns" in bundle alias "Macintosh SSD:Applications:Evernote.app:"
display dialog "Bezeichnung eingeben:
(z.B. iPad)" with title "Script by FloZi.de" default answer "" buttons {"Weiter", "Abbrechen"} default button 1 with icon alias "Macintosh SSD:Applications:Evernote.app:Contents:Resources:Evernote.icns"
end tell
tell application "Preview"
quit
end tell
tell application "Finder"
set name of document file "2016-01-01_.TEST_.TEST-TEST.pdf" of folder "test" of folder "Desktop" of folder "FloZi" of folder "Users" of startup disk to "2016-01-01_.TESTTAG1.TESTTAG2-TEST.pdf"
get selection
get document file "2016-01-01_.TESTTAG1.TESTTAG2-TEST.pdf" of folder "test" of folder "Desktop" of folder "FloZi" of folder "Users" of startup disk
end tell


Ich hoffe jemand kann mir weiterhelfen...danke schonmal

Gruß
FloZi
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    Fischer-Bayern.de Foren-Übersicht -> AppleScript X Alle Zeiten sind GMT + 2 Stunden
Seite 1 von 1

 
Gehe zu:  
Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.


Powered by phpBB © 2001, 2002 phpBB Group
Deutsche Übersetzung von phpBB.de


AppleScript für absolute Starter