Friday, May 29, 2020

#26 2020-03-27 02:39:52 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

Re: Keynote - Movie Export Droplet with ProRes 4444 @ 1920 x 1080

The real problem is to be able to identify the language which is used.
How may we know if it's "pt.lproj" or "pt_PT.lproj" which is used ?
According to that, some strings aren't localized the same way.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 27 mars 2020  09:39:46

Offline

 

#27 2020-03-27 03:27:42 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Keynote - Movie Export Droplet with ProRes 4444 @ 1920 x 1080

Yvan Koenig wrote:

How may we know if it's "pt.lproj" or "pt_PT.lproj" which is used ?


Yvan, I just haven’t done this yet, but the logic tells me that the application somehow determines which project to use. Most likely from some kind of plist file.

I know that you have been doing script localization for a long time. I need time to read your previous posts about this problem and think about it more seriously. If I find a solution, I will post it HERE.

Last edited by KniazidisR (2020-03-27 03:35:47 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#28 2020-03-27 05:19:04 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

Re: Keynote - Movie Export Droplet with ProRes 4444 @ 1920 x 1080

I got it.

Applescript:

----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

property |⌘| : a reference to current application

# List of the languages known by the application -- here the 39 ones known by iWork and by the system
set known to {"ar", "ca", "cs", "da", "de", "el", "en_AU", "en_GB", "en", "es_419", "es", "fi", "fr_CA", "fr", "he", "hi", "hr", "hu", "id", "it", "ja", "ko", "ms", "nl", "no", "pl", "pt_PT", "pt", "ro", "ru", "sk", "sv", "th", "tr", "uk", "vi", "zh_CN", "zh_HK", "zh_TW"}

# Grab the System's language setting
set currentLocale to |⌘|'s NSLocale's currentLocale()
set preferredLanguages to |⌘|'s NSLocale's preferredLanguages() as list
--> (*fr-FR, en-FR, de-FR, sv-FR, zh-Hans-FR*)
--> (*pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR, pt-BR, fr-CA*) -- use Portuguese from Portugal
--> (*pt-BR, pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR, fr-CA*) -- use Portuguese from Brazil
--> (*fr-CA, pt-BR, pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR*) -- use French from Canada

set countryCode to currentLocale's countryCode as text --> "FR" -- "FR"
set activeLanguage to item 1 of preferredLanguages
if activeLanguage ends with "-" & countryCode then set activeLanguage to text 1 thru -4 of activeLanguage
if activeLanguage is "pt-BR" then set activeLanguage to "pt" -- use pt.lproj
if activeLanguage is "zh-Hant-MO" then set activeLanguage to "zh_CN" -- use zh_CN.lproj
if activeLanguage is "zh-Hant-TW" then set activeLanguage to "zh_TW" -- use zh_TW.lproj
if activeLanguage is "no" then set activeLanguage to "nb" -- use nb.lproj
if activeLanguage contains "-" then set activeLanguage to my remplace(activeLanguage, "-", "_")
if activeLanguage is not in known then set activeLanguage to "en"
-- Now we have the key to know which string to use.


tell application "Keynote"
   set x to "1543.title"
   set loc to localized string x from table "MainMenu"
   if loc = x then
       if sys2 < 14 then
           if activeLanguage = "ar" then
               set loc to "تصدير إلى"
           else if activeLanguage = "ca" then
               set loc to "Exportar a"
           else if activeLanguage = "cs" then
               set loc to "Exportovat do"
           else if activeLanguage = "da" then
               set loc to "Eksporter til"
           else if activeLanguage = "de" then
               set loc to "Exportieren"
           else if activeLanguage = "el" then
               set loc to "Εξαγωγή σε"
           else if activeLanguage = "en_AU" then
               set loc to "Export To"
           else if activeLanguage = "en_GB" then
               set loc to "Export To"
           else if activeLanguage = "en" then
               set loc to "Export To"
           else if activeLanguage = "es_419" then
               set loc to "Exportar a"
           else if activeLanguage = "es" then
               set loc to "Exportar a"
           else if activeLanguage = "fi" then
               set loc to "Vie muodossa"
           else if activeLanguage = "fr_CA" then
               set loc to "Exporter vers"
           else if activeLanguage = "fr" then
               set loc to "Exporter vers"
           else if activeLanguage = "he" then
               set loc to "ייצא אל"
           else if activeLanguage = "hi" then
               set loc to "इसमें एक्सपोर्ट करें"
           else if activeLanguage = "hr" then
               set loc to "Eksportiraj u"
           else if activeLanguage = "hu" then
               set loc to "Exportálás"
           else if activeLanguage = "id" then
               set loc to "Ekspor Ke"
           else if activeLanguage = "it" then
               set loc to "Esporta come"
           else if activeLanguage = "ja" then
               set loc to "書き出す"
           else if activeLanguage = "ko" then
               set loc to "다음으로 내보내기"
           else if activeLanguage = "ms" then
               set loc to "Eksport Ke"
           else if activeLanguage = "nl" then
               set loc to "Exporteer naar"
           else if (activeLanguage = "no") or activeLanguage = "nb" then
               set loc to "Eksporter til"
           else if activeLanguage = "pl" then
               set loc to "Eksportuj do"
           else if activeLanguage = "pt_PT" then
               set loc to "Exportar Para"
           else if activeLanguage = "pt" then
               set loc to "Exportar Para"
           else if activeLanguage = "ro" then
               set loc to "Exportă în format"
           else if activeLanguage = "ru" then
               set loc to "Экспортировать в"
           else if activeLanguage = "sk" then
               set loc to "Exportovať ako"
           else if activeLanguage = "sv" then
               set loc to "Exportera till"
           else if activeLanguage = "th" then
               set loc to "ส่งออกไปยัง"
           else if activeLanguage = "tr" then
               set loc to "Şuraya Aktar"
           else if activeLanguage = "uk" then
               set loc to "Експортувати в"
           else if activeLanguage = "vi" then
               set loc to "Xuất ra"
           else if activeLanguage = "zh_CN" then
               set loc to "导出为"
           else if activeLanguage = "zh_HK" then
               set loc to "輸出至"
           else if activeLanguage = "zh_TW" then
               set loc to "輸出至"
           else
               set loc to "Export To"
           end if
       else -- Mojave or higher
           set loc to "Export to"
       end if
   end if
   set exportTo_loc to loc
end tell
-- or, faster:

if activeLanguage = "ar" then
   set loc to "تصدير إلى"
else if activeLanguage = "ca" then
   set loc to "Exportar a"
else if activeLanguage = "cs" then
   set loc to "Exportovat do"
else if activeLanguage = "da" then
   set loc to "Eksporter til"
else if activeLanguage = "de" then
   set loc to "Exportieren"
else if activeLanguage = "el" then
   set loc to "Εξαγωγή σε"
else if activeLanguage = "en_AU" then
   set loc to "Export To"
else if activeLanguage = "en_GB" then
   set loc to "Export To"
else if activeLanguage = "en" then
   set loc to "Export To"
else if activeLanguage = "es_419" then
   set loc to "Exportar a"
else if activeLanguage = "es" then
   set loc to "Exportar a"
else if activeLanguage = "fi" then
   set loc to "Vie muodossa"
else if activeLanguage = "fr_CA" then
   set loc to "Exporter vers"
else if activeLanguage = "fr" then
   set loc to "Exporter vers"
else if activeLanguage = "he" then
   set loc to "ייצא אל"
else if activeLanguage = "hi" then
   set loc to "इसमें एक्सपोर्ट करें"
else if activeLanguage = "hr" then
   set loc to "Eksportiraj u"
else if activeLanguage = "hu" then
   set loc to "Exportálás"
else if activeLanguage = "id" then
   set loc to "Ekspor Ke"
else if activeLanguage = "it" then
   set loc to "Esporta come"
else if activeLanguage = "ja" then
   set loc to "書き出す"
else if activeLanguage = "ko" then
   set loc to "다음으로 내보내기"
else if activeLanguage = "ms" then
   set loc to "Eksport Ke"
else if activeLanguage = "nl" then
   set loc to "Exporteer naar"
else if (activeLanguage = "no") or activeLanguage = "nb" then
   set loc to "Eksporter til"
else if activeLanguage = "pl" then
   set loc to "Eksportuj do"
else if activeLanguage = "pt_PT" then
   set loc to "Exportar Para"
else if activeLanguage = "pt" then
   set loc to "Exportar Para"
else if activeLanguage = "ro" then
   set loc to "Exportă în format"
else if activeLanguage = "ru" then
   set loc to "Экспортировать в"
else if activeLanguage = "sk" then
   set loc to "Exportovať ako"
else if activeLanguage = "sv" then
   set loc to "Exportera till"
else if activeLanguage = "th" then
   set loc to "ส่งออกไปยัง"
else if activeLanguage = "tr" then
   set loc to "Şuraya Aktar"
else if activeLanguage = "uk" then
   set loc to "Експортувати в"
else if activeLanguage = "vi" then
   set loc to "Xuất ra"
else if activeLanguage = "zh_CN" then
   set loc to "导出为"
else if activeLanguage = "zh_HK" then
   set loc to "輸出至"
else if activeLanguage = "zh_TW" then
   set loc to "輸出至"
end if
set export_loc to loc

#=====

on remplace(t, d1, d2)
   local oTIDs, l
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
   set l to text items of t
   set AppleScript's text item delimiters to d2
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end remplace

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 27 mars 2020  12:18:59

Last edited by Yvan Koenig (2020-03-27 09:41:24 am)

Offline

 

#29 2020-03-27 09:52:11 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4370

Re: Keynote - Movie Export Droplet with ProRes 4444 @ 1920 x 1080

I completed the script in my preceding message because I grabbed the missing strings.

To do that I ran the app in the 39 language it's aware of.
I used the script below adapted from a Nigel Garvey's one.
I dropped the code allowing us to choose what to do because applying to 39 versions is boring.

Applescript:

----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

property ScriptTitle : "UI Properties"

property appName : "Keynote" -- Edit to fit your needs



-- By squaline (alias partron22?), emendelson, and Nigel Garvey.
-- http://macscripter.net/viewtopic.php?id=37674

-- Edited by Yvan KOENIG (VALLAURIS, France) vendredi 27 mars 2020 16:50:14

on main()
   
   # Grab the System's language setting
   set currentLocale to current application's NSLocale's currentLocale()
   set preferredLanguages to current application's NSLocale's preferredLanguages() as list
   --> (*fr-FR, en-FR, de-FR, sv-FR, zh-Hans-FR*)
   --> (*pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR, pt-BR, fr-CA*) -- use Portuguese from Portugal
   --> (*pt-BR, pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR, fr-CA*) -- use Portuguese from Brazil
   --> (*fr-CA, pt-BR, pt-PT, fr-FR, en-FR, de-FR, zh-Hans-FR*) -- use French from Canada
   
   set countryCode to currentLocale's countryCode as text --> "FR" -- "FR"
   set activeLanguage to item 1 of preferredLanguages
   try
       tell application appName to quit
   end try
   try
       delay 0.2
       tell application appName to activate -- to force it to use the newly selected language
       
       tell application "System Events"
           tell application process appName
               set frontmost to true
               (*
               set {windowExists, menuExists} to {front window exists, menu bar 1 exists}
               
               set {winstuff, menustuff} to {"(No window open)", "(No menu!)"}
               if outputType is "Window" then
                   if (windowExists) then
                       set winstuff to my listToText(entire contents of front window)
                   else
                       error number 3000
                   end if
               else
                   if (menuExists) then
                       set menustuff to my listToText(entire contents of menu bar 1)
                   else
                       error number 3001
                   end if
               end if
               *)

               
               set outputType to "Menu"
               set menustuff to my listToText(entire contents of menu bar 1)
           end tell
       end tell
   on error e number n
       tell application "System Events" to set frontmost of application process curApp to true
       tell application curApp to activate
       if n = 3000 then
           tell application curApp to display alert "No windows to gather data from!"
           
       else if n = 3001 then
           tell application curApp to display alert "No menu to gather data from!"
       end if
       error number -128
   end try
   
   set p2d to path to desktop as text
   set dest to (p2d & activeLanguage & ".rtf") as «class furl»
   tell application "TextEdit"
       activate
       set newDoc to make new document at the front
       save newDoc in dest
       if outputType is "Window" then
           set the text of the front document to winstuff
       else
           set the text of the front document to menustuff
       end if
       set WrapToWindow to text 2 thru -1 of (localized string "&Wrap to Window")
   end tell
   
   tell application "System Events"
       tell application process "TextEdit"
           tell menu item WrapToWindow of menu 1 of menu bar item 5 of menu bar 1
               if ((it exists) and (it is enabled)) then perform action "AXPress"
           end tell
       end tell
   end tell
   --tell application curApp to activate
   do shell script "open -b \"com.apple.textedit\""
   
end main

on listToText(entireContents) -- (Handler specialised for lists of System Events references.)
   try
       || of entireContents -- Deliberate error.
   on error stuff -- Get the error message
   end try
   
   -- Parse the message.
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {"{", "}"} -- Snow Leopard or later.
   set stuff to text from text item 2 to text item -2 of stuff
   
   -- If the list text isn't in decompiled form, create a script containing the list in its source code, store it in the Temporary Items folder, and run "osadecompile" on it.
   if (stuff does not contain "application process \"") then
       try
           set scpt to (run script "script
   tell app \"System Events\"
   {"
& stuff & "}
   end
   end"
)
       on error errMsg
           set AppleScript's text item delimiters to astid
           tell application (path to frontmost application as text) to display dialog errMsg buttons {"OK"} default button 1 with icon caution
           return errMsg
       end try
       set tmpPath to (path to temporary items as text) & "Entire contents.scpt"
       store script scpt in file tmpPath replacing yes
       set stuff to (do shell script "osadecompile " & quoted form of POSIX path of tmpPath)
       set stuff to text from text item 2 to text item -2 of stuff
   end if
   
   -- Break up the text, using "\"System Events\", " as a delimiter.
   set AppleScript's text item delimiters to "\"System Events\", "
   set stuff to stuff's text items
   -- Insert a textual "reference" to the root object at the beginning of the resulting list.
   set AppleScript's text item delimiters to " of "
   set beginning of stuff to (text from text item 2 to -1 of item 1 of stuff) & "\"System Events\""
   -- Reduce the remaining "reference" fragments to object specifiers, tabbed according to the number of elements in the references.
   set tabs to tab & tab & tab & tab & tab & tab & tab & tab
   set tabs to tabs & tabs
   set tabs to tabs & tabs -- 32 tabs should be enough!
   repeat with i from 2 to (count stuff)
       set thisLine to item i of stuff
       set lineBits to thisLine's text items
       -- Make sure any " of "s in element names aren't mistaken for those of the reference!
       set elementCount to 0
       set nameContinuation to false
       repeat with j from 1 to (count lineBits)
           set thisBit to item j of lineBits
           if ((not ((nameContinuation) or (thisBit contains "\""))) or ((thisBit ends with "\"") and (thisBit does not end with "\\\"")) or (thisBit ends with "\\\\\"")) then
               -- thisBit is either a complete nameless-element specifier or it ends the right way to be either a complete named one or the completion of a name.
               set nameContinuation to false
               set elementCount to elementCount + 1
               if (elementCount is 1) then set spec to text 1 thru text item j of thisLine
           else
               -- The next "bit" will be the continuation of a name containing " of ".
               set nameContinuation to true
           end if
       end repeat
       set item i of stuff to (text 1 thru (elementCount - 3) of tabs) & spec
   end repeat
   -- Coerce back to a single text, inserting line feeds between the items.
   set AppleScript's text item delimiters to linefeed
   set stuff to stuff as text
   set AppleScript's text item delimiters to astid
   
   return stuff
end listToText

main()

Yvan KOENIG (VALLAURIS, France) vendredi 27 mars 2020  16:51:55

Offline

 

#30 2020-03-29 08:38:54 pm

BitCy
Member
Registered: 2020-01-12
Posts: 11

Re: Keynote - Movie Export Droplet with ProRes 4444 @ 1920 x 1080

KniazidisR wrote:

The solution founded.

Mm, yes. I barely figured it out ... It turns out that you first need to focus the text field. Otherwise, Keynote ignores the new values:

Applescript:


set movieName to "myNewKeynoteMovie"

tell application id "com.apple.systemevents" to tell process "Keynote"
   
   set frontmost to true
   tell menu bar 1 to tell menu bar item "File" to tell menu 1
       tell menu item "Export To" to tell menu 1 to click menu item "Movie…"
   end tell
   
   delay 0.1
   tell window 1 to tell sheet 1
       
       tell (1st text field whose help is "Type how many seconds to wait between slides.")
           set focused to true -- ADDED
           set value to "1"
       end tell
       tell (1st text field whose help is "Type how many seconds to wait between builds.")
           set focused to true -- ADDED
           set value to "0"
       end tell
       delay 1
       
       tell (1st pop up button whose help is "Choose a size for the movie.")
           perform action "AXShowMenu"
           delay 0.1
           click menu item "Custom..." of menu 1
       end tell
       set value of 1st text field whose help is "Type the width you want for the movie." to "1920"
       set value of 1st text field whose help is "Type the height you want for the movie." to "1080"
       
       click (1st radio button whose title is "Apple ProRes 4444")
       delay 0.1
       click button "Next…"
   end tell
   
   delay 1
   click text field 1 of sheet 1 of window 1
   keystroke movieName & return -- naming the movie
   delay 1
   repeat while sheet 1 of window 1 exists -- show creating movie progress
       delay 0.1
   end repeat
   
end tell



Thanks for this KniazidisR! Did not know the issue was focusing the text field11

Yvan Koenig, I have combined part of KniazidisR's code into yours. Now it seems to work. Durations are the same.

Applescript:


(*
-- code dropped because it doesn't apply when the app is used in French.
Apple forgot to insert the file: "Keynote.app:Contents:Resources:fr.lproj:MainMenu.strings". They put a MainMenu.nib file.
Happily, there is a clone available as :
"Keynote.app:Contents:Resources:fr_CA.lproj:MainMenu.strings"
On my copy I duplicated the file so now the code works.
Maybe the file is available in versions newer than 9.1
Same odd omission in Pages and Numbers
As the numbering of menu items doesn't change since several years, I choose to trigger the menu items by their index.

tell application "Keynote"
set exportTo_loc to localized string "1543.title" from table "MainMenu" --> "Exporter vers"
end tell
*)


set indexFile to 3 -- index of menu "File" ("Fichier")
set indexExportTo to 14 -- index of menu item "Export To" ("Exporter vers")
set indexMovie to 3 -- index of menu item "Movie…" ("Vidéo…")

tell application id "com.apple.systemevents" to tell process "Keynote"
   set frontmost to true
   tell menu bar 1
       -- get name of menu bar items --> {"Apple", "Keynote", "Fichier", "Édition", "Insérer", "Diapositive", "Format", "Disposition", "Présentation", "Lecture", "Partager", "Fenêtre", "Aide"}
       -- get name of menu bar item indexFile --> "Fichier"
       tell menu bar item indexFile to tell menu 1
           -- get name of menu items --> {"Nouveau", "Créer à partir de la liste de thèmes…", "Ouvrir…", "Ouvrir un document récent", missing value, "Fermer", "Tout fermer", "Enregistrer", "Enregistrer sous…", "Dupliquer", "Renommer…", "Déplacer vers…", "Revenir à", "Exporter vers", missing value, "Réduire la taille du fichier…", "Avancé", missing value, "Définir un mot de passe…", missing value, "Modifier le thème…", "Enregistrer le thème…", missing value, "Imprimer…"}
           -- get name of menu item indexExportTo --> "Exporter vers"
           tell menu item indexExportTo to tell menu 1
               -- get name of menu items --> {"PDF…", "PowerPoint…", "Vidéo…", "GIF animé…", "Images…", "HTML…", "Keynote ’09…"}
               -- get name of menu item indexMovie --> "Vidéo…"
               click menu item indexMovie
           end tell -- menu item indexMovie
       end tell -- menu bar item indexFile
   end tell -- menu bar 1
   -- class of UI elements
   tell (first window whose subrole is "AXStandardWindow") -- EDITED
       
       class of UI elements --> {radio group, checkbox, static text, scroll area, scroll area, scroll area, button, button, button, menu button, toolbar, image, static text, sheet}
       
       
       tell sheet 1
           -- class of UI elements --> {static text, list, static text, pop up button, static text, text field, static text, static text, text field, static text, static text, static text, text field, static text, text field, radio button, radio button, static text, pop up button, static text, button, button, button}
           -- help of text fields --> {"Saisissez le nombre de secondes d’attente entre chaque diapositive.", "Saisissez le nombre de secondes d’attente entre chaque composition.", missing value, missing value} -- ADDED
           tell (1st text field whose help is "Type how many seconds to wait between slides.")
               set focused to true -- ADDED
               set value to "1"
           end tell
           tell (1st text field whose help is "Type how many seconds to wait between builds.")
               set focused to true -- ADDED
               set value to "0"
           end tell
           delay 0.1
           -- help of pop up button 1 --> "Choisissez le mode de lecture de la vidéo."
           -- help of pop up button 2 --> "Choisissez une taille pour la vidéo."
           tell pop up button 2
               its value --> "1024 x 768"
               click it
               repeat 50 times
                   if exists menu 1 then exit repeat
                   delay 0.2
               end repeat
               tell menu 1
                   -- class of UI elements --> {menu item, menu item, menu item, menu item}
                   -- name of menu items --> {"1024 x 768", "720p", "1080p", "Personnaliser…"}
                   click menu item -1 -- Custom
               end tell
           end tell
           set checkBoxAvailable to (class of UI elements) contains checkbox --> {static text, list, static text, pop up button, static text, text field, static text, static text, text field, static text, static text, static text, text field, static text, text field, radio button, radio button, static text, pop up button, text field, static text, text field, static text, static text, checkbox, radio button, radio button, radio button, button, button, button}
           
           -- help of text field -2 --> "Saisissez la largeur voulue pour la vidéo."
           -- help of text field -1 --> "Saisissez la hauteur voulue pour la vidéo."
           -- value of text field -2 --> "1024"
           -- value of text field -1 --> "768"
           set value of text field -2 to "1920" -- must be a string
           set value of text field -1 to "1080" -- must be a string
           
           -- name of radio button -3 --> "Apple ProRes 422"
           -- name of radio button -2 --> "H.264"
           -- name of radio button -1 --> "Apple ProRes 4444"
           click radio button -1
           if checkBoxAvailable then
               -- name of checkbox 1 --> "Exporter avec des arrière-plans transparents"
               value of checkbox 1 --> 1
               
               -- set value of checkbox 1 to 1 -- enable it to check the box
               -- set value of checkbox 1 to 0 -- enable it to uncheck the box
           end if
           
       end tell -- sheet 1
       
   end tell
end tell -- System Events

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)