Variabel an anderes AppleScript weitergeben?

leo-magic

Aktives Mitglied
Thread Starter
Dabei seit
24.12.2004
Beiträge
1.178
Reaktionspunkte
4
Hallo zusammen

Vielleicht kenn jemand die Antwort... Wie kann ich die Variabel "signature", die im ersten Teil meines Scripts gesetzt wird an das Script "printScript.scpt", welches mit on load_run geladen wird, weitergeben?

Werde nicht schlau aus dem set main_property of this_script to this_property_value....?

Danke für eure Hilfe!

Léo

AppleScript:
on open location this_url
    
    -- EXTRACT ARGUMENTS
    set x to the offset of "?" in this_url
    set the argument_string to text from (x + 1) to -1 of this_url
    set AppleScript's text item delimiters to "&"
    set these_arguments to every text item of the argument_string
    set AppleScript's text item delimiters to ""
    
    -- PROCESS ACTIONS
    -- This loop will execute scripts located within the Resources folder
    -- of this applet depending on the key and value passed in the URL
    repeat with i from 1 to the count of these_arguments
        set this_pair to item i of these_arguments
        set AppleScript's text item delimiters to "="
        copy every text item of this_pair to {this_key, this_value}
        set AppleScript's text item delimiters to ""
        if this_key is "signature" then
            set signature to this_value
            if my run_scriptfile("printScript.scpt") is false then error number -128
        end if
    end repeat
end open location

on run_scriptfile(this_scriptfile)
    -- This handler will execute a script file
    -- located in the Resources folder of this applet
    try
        set the script_file to path to resource this_scriptfile
        return (run script script_file)
    on error
        return false
    end try
end run_scriptfile

on load_run(this_scriptfile, this_property_value)
    -- This handler will load, then execute, a script file
    -- located in the Resources folder of this applet.
    -- This method allows you to change property values
    -- within the loaded script before execution,
    -- or to execute handlers within the loaded script.
    try
        set the script_file to path to resource this_scriptfile
        
        set this_script to load script script_file
        set main_property of this_script to this_property_value
        
        return (run script this_script)
        
    on error
        return false
    end try
end load_run
 
Danke für den hilfreichen Link. Das verstehe ich soweit... Aber was hat es mit dem auf sich?

set this_script to load script script_file
set main_property of this_script to this_property_value

Was bezweckt das? Bzw. wie kann ich meine Variable "signature" da einschliessen?
 
Das nutzt du doch gar nicht.
An sich musst du run_scriptfile erweitern mit Parameter und den dann auch an das andere Script übergeben.
 
Stimmt. Ok dumm. Sorry. :whistle:

Habe es nun so versucht:

Code:
on run_scriptfile(this_scriptfile, signature)
    -- This handler will execute a script file
    -- located in the Resources folder of this applet
    try
        set the script_file to path to resource this_scriptfile
        return (run script script_file with parameters {signature})
    on error
        return false
    end try
end run_scriptfile

und in der Skriptdatei:

Code:
on run {signature}

EDIT: So gehts. super, danke!!
 
Wegen Scope wird der signature nicht kennen, solltest du auch an run_script mit übergeben.

Wertet der denn signature unter dem Namen im zweiten Script aus?
 
Hast du meinen EDIT noch rechtzeitig gesehen?
 
Super, danke! Auf jeden Fall klappt so alles.

Falls es jemanden interessiert, was das Script überhaupt macht:

Zweck: Ein PDF ohne Druckdialoge und sonstigen Eingabeaufforderungen direkt von einer (eigenen) Website (im Kiosk Modus) drucken.

Beim Klick auf "Drucken" bzw. Druckbefehl über Javascript:

1) Ein PHP script kopiert die zu druckende PDF-Datei in ein "print_queue" Verzeichnis und fügt der Datei ein Prefix (signature + printer id) zu.
2) Das Applescript wird über JS aufgerufen. (custom URL scheme)
3) Das Apple Script lädt die PDF-Datei via ftp (und löscht sie auf dem server), überprüft den Prefix (druckt nur Datei mit entsprechender signature aus dem aktuellen Druckauftrag) und druckt es auf dem Drucker mit entsprechender "printer id"
4) Apple Script löscht die heruntergeladene Datei nach dem Drucken.

Habe leider keine einfachere Lösung gefunden, um die Druckdialoge etc. zu umgehen beim Drucken aus dem Browser...

Falls jemand Interesse hat am Script oder es optimieren möchte, gerne melden. :)

Gruss

Léo
 
  • Gefällt mir
Reaktionen: mausfang
Ein Problem besteht noch...

Wenn sich das Script in einem Verzeichnis befindet, welches einen Leerschlag im Namen hat (zB. "Print Script") funktioniert dieser Code nicht.
Wie kann ich das abändern, damit es auch funktioniert mit Leerschlägen in Verzeichnisnamen?

Danke und Gruss

Léo

AppleScript:
on run_scriptfile(this_scriptfile, signature)
    try
        set the script_file to path to resource this_scriptfile
        return (run script script_file with parameters {signature})
    on error
        return false
    end try
end run_scriptfile
 
Zurück
Oben Unten