• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

[AppleScript] XLM Datei Speichern über Dialog Text Input ?

flashi

Alkmene
Registriert
11.01.19
Beiträge
32
Ich bräuchte mal eure Hilfe. Das einlesen in Dialog Text Input habe ich hinbekommen aber wie speichere ich jetzt ab!? Ich finde auch nichts im Netz. Ich lese immer das eine Xml keine Speicher Funktion in Applescript hat?

FFmpeg Edit.scpt (Beispiel)
Code:
set xmlData to ((path to documents folder as string) & "FFmpeg Edit.cfg")
tell application "System Events"
    tell XML element "FFmpegEdit" of contents of XML file xmlData
        set GlobalOptions to (value of XML element "GlobalOptions")
    end tell
end tell

display dialog "Global Options:" default answer GlobalOptions buttons {"Abort", "Save"} with title "FFmpeg Edit"
if the button returned of the result is "Save" then
    
    -- Save GlobalOptions?
    
end if

FFmpeg Edit.cfg (Beispiel)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<FFmpegEdit>
    <GlobalOptions>-y</GlobalOptions>
</FFmpegEdit>
 

flashi

Alkmene
Registriert
11.01.19
Beiträge
32
Ich habe eine eigene Lösung gefunden. Hat eine weile gedauert aber es geht.

Code:
set filepath to ((path to documents folder as string) & "FFmpeg Edit.xml")

-- write

on xmlheader()

return "<?xml version=\"1.0\" encoding=\"utf-8\"?>"

end xmlheader


on GlobalOptionsTag(txt)

return "<GlobalOptions>" & txt & "</GlobalOptions>"

end GlobalOptionsTag


on InputOptionsTag(txt)

return "<InputOptions>" & txt & "</InputOptions>"

end InputOptionsTag


on OutputOptionsTag(txt)

return "<OutputOptions>" & txt & "</OutputOptions>"

end OutputOptionsTag


on OutputFormatTag(txt)

return "<OutputFormat>" & txt & "</OutputFormat>"

end OutputFormatTag


on writetofile(cont, filepath)

try

set openfile to open for access filepath with write permission

set eof of openfile to 0

set BOM_UTF8 to ((ASCII character 239) & (ASCII character 187) & (ASCII character 191))

write BOM_UTF8 to openfile

write cont to openfile as «class utf8»

close access openfile

return true

on error

try

close access openfile

end try

return false

end try

end writetofile


-- read

tell application "System Events"

tell XML element "FFmpegEdit" of contents of XML file filepath

set GlobalOptions to (value of XML element "GlobalOptions")

set InputOptions to (value of XML element "InputOptions")

set OutputOptions to (value of XML element "OutputOptions")

set OutputFormat to (value of XML element "OutputFormat")

end tell

end tell

set {text returned:GlobalOptions} to (display dialog "Global Options:" default answer GlobalOptions buttons {"Abort", "Save"} with title "FFmpeg Edit")

if the button returned of the result is "Save" then

set xmlData to xmlheader() & return

set xmlData to xmlData & "<FFmpegEdit>" & return

set xmlData to xmlData & my GlobalOptionsTag(GlobalOptions) & return

set xmlData to xmlData & my InputOptionsTag(InputOptions) & return

set xmlData to xmlData & my OutputOptionsTag(OutputOptions) & return

set xmlData to xmlData & my OutputFormatTag(OutputFormat) & return

set xmlData to xmlData & "</FFmpegEdit>"

my writetofile(xmlData, filepath)

end if

set {text returned:InputOptions} to (display dialog "Input Options:" default answer InputOptions buttons {"Abort", "Save"} with title "FFmpeg Edit")

if the button returned of the result is "Save" then

set xmlData to xmlheader() & return

set xmlData to xmlData & "<FFmpegEdit>" & return

set xmlData to xmlData & my GlobalOptionsTag(GlobalOptions) & return

set xmlData to xmlData & my InputOptionsTag(InputOptions) & return

set xmlData to xmlData & my OutputOptionsTag(OutputOptions) & return

set xmlData to xmlData & my OutputFormatTag(OutputFormat) & return

set xmlData to xmlData & "</FFmpegEdit>"

my writetofile(xmlData, filepath)

end if

set {text returned:OutputOptions} to (display dialog "Output Options:" default answer OutputOptions buttons {"Abort", "Save"} with title "FFmpeg Edit")

if the button returned of the result is "Save" then

set xmlData to xmlheader() & return

set xmlData to xmlData & "<FFmpegEdit>" & return

set xmlData to xmlData & my GlobalOptionsTag(GlobalOptions) & return

set xmlData to xmlData & my InputOptionsTag(InputOptions) & return

set xmlData to xmlData & my OutputOptionsTag(OutputOptions) & return

set xmlData to xmlData & my OutputFormatTag(OutputFormat) & return

set xmlData to xmlData & "</FFmpegEdit>"

my writetofile(xmlData, filepath)

end if

set {text returned:OutputFormat} to (display dialog "Output Format:" default answer OutputFormat buttons {"Abort", "Save"} with title "FFmpeg Edit")

if the button returned of the result is "Save" then

set xmlData to xmlheader() & return

set xmlData to xmlData & "<FFmpegEdit>" & return

set xmlData to xmlData & my GlobalOptionsTag(GlobalOptions) & return

set xmlData to xmlData & my InputOptionsTag(InputOptions) & return

set xmlData to xmlData & my OutputOptionsTag(OutputOptions) & return

set xmlData to xmlData & my OutputFormatTag(OutputFormat) & return

set xmlData to xmlData & "</FFmpegEdit>"

my writetofile(xmlData, filepath)

end if

FFmpeg Edit.xml

Code:
<?xml version="1.0" encoding="utf-8"?>

<FFmpegEdit>

<GlobalOptions>-y</GlobalOptions>

<InputOptions>-i</InputOptions>

<OutputOptions>-threads 1 -preset fast -c:a aac -b:a 192k -c:v libx264 -vf scale=854:480</OutputOptions>

<OutputFormat>mp4</OutputFormat>

</FFmpegEdit>
 

flashi

Alkmene
Registriert
11.01.19
Beiträge
32
Es ist doch noch nicht ganz Bug frei. Wenn zbs. bei <GlobalOptions></GlobalOptions> nichts steht wird aber im Display Dialog Text Input aber was angezeigt. Siehe Bild. Habt ihr da eine Lösung?
 

Anhänge

  • Bildschirmfoto 2019-02-27 um 16.34.46.png
    Bildschirmfoto 2019-02-27 um 16.34.46.png
    466,9 KB · Aufrufe: 4

flashi

Alkmene
Registriert
11.01.19
Beiträge
32
Ich habe eine bessere Lösung gefunden. Ich nutze jetzt Plist stat xml.

FFmpeg Edit.app
Code:
-- ==================================================================

-- FFmpeg Edit.app v1.3

-- ==================================================================

#set theicon to alias ((path to me as text) & "Contents:Resources:applet.icns")


on savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

set plistfile_path to ((path to documents folder as string) & "FFmpeg Edit.plist")

tell application "System Events"

set the parent_dictionary to make new property list item with properties {kind:record}

set this_plistfile to make new property list file with properties {contents:parent_dictionary, name:plistfile_path}

make new property list item at end of property list items of contents of this_plistfile with properties {name:"FFmpegPath", value:FFmpegPath}

make new property list item at end of property list items of contents of this_plistfile with properties {name:"GlobalOptions", value:GlobalOptions}

make new property list item at end of property list items of contents of this_plistfile with properties {name:"InputOptions", value:InputOptions}

make new property list item at end of property list items of contents of this_plistfile with properties {name:"OutputOptions", value:OutputOptions}

make new property list item at end of property list items of contents of this_plistfile with properties {name:"OutputFormat", value:OutputFormat}

end tell

end savePlist


tell application "System Events"

set filepath to ((path to documents folder as string) & "FFmpeg Edit.plist")

set p_list to property list file (filepath)

set FFmpegPath to value of property list item "FFmpegPath" of p_list

set GlobalOptions to value of property list item "GlobalOptions" of p_list

set InputOptions to value of property list item "InputOptions" of p_list

set OutputOptions to value of property list item "OutputOptions" of p_list

set OutputFormat to value of property list item "OutputFormat" of p_list

end tell


set {text returned:FFmpegPath} to (display dialog "FFmpeg Path:" default answer FFmpegPath buttons {"Abort", "Save"} with title "FFmpeg Edit") # with icon theicon)

if the button returned of the result is "Save" then

savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

end if


set {text returned:GlobalOptions} to (display dialog "Global Options:" default answer GlobalOptions buttons {"Abort", "Save"} with title "FFmpeg Edit") # with icon theicon)

if the button returned of the result is "Save" then

savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

end if


set {text returned:InputOptions} to (display dialog "Input Options:" default answer InputOptions buttons {"Abort", "Save"} with title "FFmpeg Edit") # with icon theicon)

if the button returned of the result is "Save" then

savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

end if


set {text returned:OutputOptions} to (display dialog "Output Options:" default answer OutputOptions buttons {"Abort", "Save"} with title "FFmpeg Edit") # with icon theicon)

if the button returned of the result is "Save" then

savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

end if


set {text returned:OutputFormat} to (display dialog "Output Format:" default answer OutputFormat buttons {"Abort", "Save"} with title "FFmpeg Edit") # with icon theicon)

if the button returned of the result is "Save" then

savePlist(FFmpegPath, GlobalOptions, InputOptions, OutputOptions, OutputFormat)

end if

FFmpeg Edit.plist
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>FFmpegPath</key>
    <string>/usr/local/bin/</string>
    <key>GlobalOptions</key>
    <string>-y</string>
    <key>InputOptions</key>
    <string>-i</string>
    <key>OutputFormat</key>
    <string>mp4</string>
    <key>OutputOptions</key>
    <string>-threads 1 -preset fast -c:a aac -b:a 192k -c:v libx264 -vf scale=854:480</string>
</dict>
</plist>