Applescript, neue Powerpoint-Datei in Ordner erstellen

D

DvdH1979

Mitglied
Thread Starter
Dabei seit
03.06.2020
Beiträge
51
Reaktionspunkte
16
Hallo zusammen,

nachdem ich mich ein wenig mit dem Automator beschäftigt habe, bekomme ich richtig Spaß daran.

Habe mir ein kleines Script gebastelt, das mit Klick auf einen Ordner als Schnellaktion neue Office-Dokumente anlegen soll.
Excel und Word funktionieren wie gewünscht, aber PowerPoint will einfach nicht den Dateinamen übernehmen, den ich angebe - es wird einfach "Präsentation1" usw. genannt.

Hier das Script:
AppleScript:
on run {input, parameters}
    ---- Office-Applikation auswählen
    set applicationList to {"Excel", "Word", "PowerPoint"}
    activate
    choose from list applicationList with prompt "Applikation auswählen" default items "Word"
    set applicationChoice to result as text
  
    set docbasename to text returned of (display dialog "Dateiname:" default answer "")
    set folderPath to POSIX path of input
  
    ---- Dateiname abhängig von gewählter Applikation setzen
    if applicationChoice = "Excel" then set savePath to (folderPath & docbasename & ".xlsx") as string
    if applicationChoice = "Word" then set savePath to (folderPath & docbasename & ".docx") as string
    if applicationChoice = "PowerPoint" then set savePath to (folderPath & docbasename & ".pptx") as string
  
    --- neues Dokument in Abhängigkeit von gewählter Applikation erzeugen
    if applicationChoice = "Excel" then
        tell application "Microsoft Excel"
            activate
            make new workbook
            save active workbook in savePath
        end tell
    end if
  
    if applicationChoice = "Word" then
        tell application "Microsoft Word"
            activate
            make new document
            save active document in savePath
        end tell
    end if
  
    if applicationChoice = "PowerPoint" then
        tell application "Microsoft PowerPoint"
            activate
            set docbasename to make new presentation
            save active presentation in savePath
        end tell
    end if
  
end run
PowerPoint scheint eine extra Behandlung zu brauchen bzgl. Speichern, damit es mit dem Namen funktioniert, aber welche?
Danke schon einmal für jeden Tipp!
 
Zuletzt bearbeitet von einem Moderator:
Wenn Du möchtest, dass man Deinen Code auch "gerne" liest ...

322689-74285bb9206db82d3f18f44d6ace722b.png


Dann poste so etwas doch bitte in Code Tags ...
 
  • Gefällt mir
Reaktionen: Difool
Ich kenne AppleScript nicht, aber: Gibt es einen Grund für die im Vergleich zu Word oder Excel abweichende Syntax der »set«/»make«-Zeile für PowerPoint?
 
Du suchst Dein Problem im Skript ... ich glaube das ist nicht das Problem.

Habe folgendes im Skripteditor ausprobiert:

AppleScript:
on run {}
    ---- input-Variable hartcodiert
    set input to (path to desktop folder)
  
    ---- Office-Applikation auswählen
    set applicationList to {"Excel", "Word", "PowerPoint"}
    activate
    choose from list applicationList with prompt "Applikation auswählen" default items "Word"
    set applicationChoice to result as text
  
    set docbasename to text returned of (display dialog "Dateiname:" default answer "")
    set folderPath to POSIX path of input
  
    ---- Dateiname abhängig von gewählter Applikation setzen
    if applicationChoice = "Excel" then set savePath to (folderPath & docbasename & ".xlsx") as string
    if applicationChoice = "Word" then set savePath to (folderPath & docbasename & ".docx") as string
    if applicationChoice = "PowerPoint" then set savePath to (folderPath & docbasename & ".pptx") as string
  
    --- neues Dokument in Abhängigkeit von gewählter Applikation erzeugen
    if applicationChoice = "Excel" then
        tell application "Microsoft Excel"
            activate
            make new workbook
            save active workbook in savePath
        end tell
    end if
  
    if applicationChoice = "Word" then
        tell application "Microsoft Word"
            activate
            make new document
            save active document in savePath
        end tell
    end if
  
    if applicationChoice = "PowerPoint" then
        tell application "Microsoft PowerPoint"
            activate
            set docbasename to make new presentation
            save active presentation in savePath
        end tell
    end if
  
end run

Funktioniert auch mit Powerpoint einwandfrei ... Die Datei heißt so, wie ich es im Dialog eingebe.

Das Einzige was ich gemacht habe, damit es im Skript-Editor läuft ist die Parameter aus dem Run-Handler genommen, damit ich es manuell starten kann.
Darum habe ich für die Input-Variable den Schreibtisch hartcodiert.

Bei mir ist es Powerpoint 2011. Dein Code ist also grundsätzlich lauffähig.
 
Vielen Dank fürs Ausprobieren, mausfang!

Merkwürdig, dass es bei Dir funktioniert.

Ich verwende die Office 365 Applikationen, evtl. ist hier der Unterschied zu vorherigen Versionen von Powerpoint.

Hat vielleicht jemand mit Office 365 die Möglichkeit, das zu verifizieren, indem es bei ihm ebenfalls nicht funktioniert?
 
Ich hab’s noch nicht als Automator-Service getestet …

ich würde Dir vorschlagen mal zu schauen ob mein Code bei Dir im normalen Skripteditor funktioniert.
 
Merkwürdig, dass es bei Dir funktioniert.

Ich verwende die Office 365 Applikationen, evtl. ist hier der Unterschied zu vorherigen Versionen von Powerpoint.
Ok ... ich bin jetzt gerade an einem anderen Mac ... und hier habe ich auch Probleme mit Powerpoint. Es ist hier die aktuelle Office365-Version von PowerPoint installiert.
Bildschirmfoto 2021-11-08 um 19.02.14.png

Die Datei wird hier bei mir gar nicht gespeichert.

Ich bin mir schon ziemlich sicher, dass das ein Bug ist ...

Der Befehl "save" ohne Pfad oder Spezifikation des Speicherformats funktioniert nämlich ohne Probleme (wenn man ein bereits gesichertes Dokument hat, und dieses ändert ... dann sichert der Save-Befehl die Änderungen in die aktuelle Datei).

Edit: Habs hinbekommen! Logisch ist das aber nicht.

AppleScript:
tell application "Microsoft PowerPoint"
    activate
    tell active presentation
        -- das hier funktioniert:
        set newPath to ((path to desktop folder) as string) & "test2.pptx"
        -- ergibt bei mir als newPath: (*Macintosh HD:Users:stefankopec:Desktop:test2.pptx*)
        -- was nicht funktionierte war der POSIX-Path: 
        -- set newPath to POSIX path of (path to desktop folder) & "test2.pptx"
        -- ergab bei mir als newPath: (*/Users/stefankopec/Desktop/test3.pptx*) -- GEHT NICHT, WARUM AUCH IMMER, denn Word und Excel schlucken das ja
        log newPath
        save in newPath
    end tell
end tell
 
Zuletzt bearbeitet:
Zurück
Oben Unten