Créer un nouveau fichier texte

Posté le 21 janvier, 2009 dans AppleScript, Mac | Aucun Commentaire »

Voici comment créer un fichier texte rapidement dans le dossier actuellement sélectionné dans le Finder :

tell application "Finder"
  set pwdAlias to insertion location as alias
  if not (exists folder pwdAlias) then
    set pwdAlias to (container of pwdAlias) as alias
  end if
  set pwd to POSIX path of pwdAlias
  do shell script "touch \"" & pwd & "/Nouveau.txt\""
end tell

Placer ce script dans le dossier /Users/%USER%/Library/Scripts pour pouvoir l’utiliser depuis la barre de menu du Finder.

Boucler sur les fichiers sélectionnés du Finder

Posté le 13 janvier, 2009 dans AppleScript, Mac | Aucun Commentaire »

Voici un petit script AppleScript qui permet de boucler sur les fichiers actuellement sélectionnés dans la fenêtre courante du Finder :

tell application "Finder"
  set selectedFiles to selection
  repeat with oneFile in selectedFiles
    -- posixPath = chemin du fichier avec des /
    -- macPath = chemin du fichier avec des :
    set posixPath to (POSIX path of (oneFile as alias))
    set macPath to (oneFile as alias)
    log posixPath
    log macPath
  end repeat
end tell