2011-10-05 3 views
1

Je veux créer un script qui enregistrera des documents safari en utilisant les événements système (commande + s) et je veux que le fichier soit toujours sauvegardé sur un chemin particulier. (Je pourrais prendre l'habitude de toujours enregistrer les fichiers safari dans un certain dossier mais ce n'est pas une solution robuste.) Comment puis-je m'assurer que les événements système enregistrent un document sur un certain chemin?applescript: comment choisir automatiquement d'enregistrer un document safari dans un CHEMIN PARTICULIER avec des événements système

Répondre

1

Directement à partir this MacRumors forum post:

tell application "Safari" 
    activate 
end tell 

tell application "System Events" 
    tell process "Safari" 
     click menu item "Copy" of menu "Edit" of menu bar 1 
    end tell 
end tell 

delay 1 

set the_filename to (the clipboard) & ".html" 
set the_filepath to "Macintosh HD:Users:Roy:Documents:" & the_filename 
set the_shellfilepath to "'/Users/Roy/Documents/" & the_filename & ".download'" 
set the_shellfilepath2 to "'/Users/Roy/Documents/" & the_filename & "'" 

tell application "Safari" 
    activate 
    save document 1 in the_filepath 
end tell 

do shell script "mv " & the_shellfilepath & " " & the_shellfilepath2 

Définir le chemin (the_shellfilepath), selon le cas.

1

Changer le dossier d'une boîte de dialogue de fichier:

try 
    try -- this would result in an error when there's no clipboard 
     set old to the clipboard 
    end try 
    -- delay 1 -- for testing 
    -- activate application "Safari" 
    tell application "System Events" 
     keystroke "s" using command down 
     keystroke "g" using {shift down, command down} 
     delay 0.1 
     set the clipboard to "~/Movies/" 
     delay 0.1 
     keystroke "av" using command down 
     delay 0.1 
     keystroke return 
     delay 0.1 
    end tell 
    set the clipboard to old 
end try 

Enregistrer dans un dossier spécifique avec une URL partiellement codé comme un nom de fichier:

tell application "Safari" 
    set x to URL of document 1 
    set r to do shell script "echo " & quoted form of x & " | sed 's|/$||;s|:|%3A|g;s|/|%2F|g'" 
    do shell script "curl " & x & " > " & quoted form of ((system attribute "HOME") & "/Desktop/" & r & ".html") 
end tell 

Enregistrer dans un dossier spécifique mais en choisissant le fichier nom manuellement:

tell application "Safari" 
    set x to URL of document 1 
    set answer to text returned of (display dialog "" default answer ".html") 
    do shell script "curl " & x & " > " & quoted form of ((system attribute "HOME") & "/Desktop/" & answer) 
end tell 
Questions connexes