Pages

Affichage des articles dont le libellé est AppleScript : Script objects. Afficher tous les articles
Affichage des articles dont le libellé est AppleScript : Script objects. Afficher tous les articles

3 juin 2011

Histoire d'Héritage

script pomme
property couleur : "ROUGE"
on afficherCouleur()
display alert "Script pomme" message "Cette pomme est " & couleur buttons {"OK"} default button 1
display alert "Script pomme" message "Cette pomme est " & couleur of me buttons {"OK"} default button 1
end afficherCouleur
end script

script banane
property parent : pomme
property couleur : "JAUNE"
on afficherCouleur()
display alert "Script banane" message "Cette banane est " & couleur buttons {"OK"} default button 1
continue afficherCouleur()
end afficherCouleur
end script

script poire
property parent : banane
property couleur : "VERTE"
end script

tell pomme to afficherCouleur()
--  affiche sa propriété : "Cette pomme est ROUGE"
--  affiche sa propriété : "Cette pomme est ROUGE"
tell banane to afficherCouleur()
--  affiche sa propriété : "Cette banane est JAUNE"
--  puis transmet au parent qui affiche sa propriété  : "Cette pomme est ROUGE"
--  et  affiche la propriété du fils : "Cette pomme est JAUNE"
tell poire to afficherCouleur()
--  transmet au parent qui affiche sa propriété  : "Cette banane est JAUNE"
--  qui transmet au grand-parent qui affiche sa propriété : "Cette pomme est ROUGE"
--  et  affiche la propriété du petit-fils : "Cette pomme est VERTE"

>> Ouvrir le script dans l'éditeur

8 nov. 2009

Plug-in Manager

tell SwitchFile to getProperties()
if the result is {"", ""} then tell SwitchFile to setProperties(choose folder with prompt "activated items :", choose folder with prompt "Inactivated items :")
tell SwitchFile to process()

script SwitchFile
property folderA : "" -- chemin d'accès au dossier contenant les items activés
property folderB : "" -- chemin d'accès au dossier contenant les items inactivés
property theMark : "√"
-- retourne le chemin d'accès des dossiers items activés/desactivés
on getProperties()
return {folderA, folderB}
end getProperties
-- enregistre le chemin d'accès des dossiers items activés/desactivés
on setProperties(a, b)
set folderA to a
set folderB to b
end setProperties
-- Boite de dialogue d'activation/desactivation des items
on process()
tell application "Finder"
set fileNameA to my addgizmo2List(theMark, the name of every file of folder folderA)
set fileNameB to the name of every file of folder folderB
set filesToMove to (choose from list (fileNameA & fileNameB) with prompt "Select items to switch :" with multiple selections allowed)
if filesToMove is not false then
repeat with fileName in filesToMove
if fileName starts with theMark then
set fileName to my deletegizmo(theMark, fileName) as string
my moveitem(folderA, folderB, fileName)
else
my moveitem(folderB, folderA, fileName)
end if
end repeat
end if
end tell
end process
-- deplacement d'un item d'un dossier vers un autre 
on moveitem(folderA, folderB, fileName)
tell application "Finder"
move (every file of folderA whose name is fileName) to folderB
end tell
end moveitem
-- coche l'item qui se trouve dans le dossier des items activés
on addgizmo2List(gizmo, theList)
set temp to {}
repeat with theItem in theList
copy ((gizmo & theItem) as string) to the end of temp
end repeat
return temp
end addgizmo2List
-- décoche l'item désactivé qui se trouve dans le dossier des items inactivés
on deletegizmo(gizmo, theText)
if theText starts with gizmo then return (characters 2 thru -1 of theText) as string
return theText
end deletegizmo
end script

Ce gestionnaire rudimentaire de plug-in illustre la réflexion de Gwénaël à propos des objets scripts >>ici

>>Ouvrir le script dans l'éditeur

6 juil. 2008

DataBase (5/5)

on read_file(thePath)
try
set thePath to thePath as string
set idFile to open for access file thePath
set fileData to read idFile as list
close access idFile
on error errMsg number errNum
close access file thePath
return false
end try
return fileData
end read_file

on write_file(theText, thePath)
try
set thePath to thePath as string
set idFile to open for access file thePath with write permission
write theText to idFile starting at 0 as list
close access id_file
return true
on error
close access file thePath
return false
end try
end write_file

-- Check the entry in a dialog box who must not be empty
on checkEmptyDialog(theText, defaultAnswer)
repeat
set theAnswer to text returned of (display dialog theText default answer defaultAnswer with icon 1)
if (count theAnswer) > 0 then exit repeat
end repeat
return theAnswer
end checkEmptyDialog

-- Return the number of one item in a list
on ItemNumber(theItem, theList)
repeat with NumItem from 1 to count theList
if theItem = item NumItem of theList then return NumItem
end repeat
return 0
end ItemNumber

on ASTID(x) -- set  item delimiter to x
set AppleScript's text item delimiters to x
end ASTID

>>Ouvrir le script dans l'éditeur

DataBase (4/5)

on createCard(a, b, c, d, e)
script
property item1 : a -- Auteur
property item2 : b -- Titre
property item3 : c -- Sujet
property item4 : d -- Edition
property item5 : e -- critere tri
on getInfos()
if item5 is "Auteur" then
return item1 & " • " & item2 & " • " & item3 & " • " & item4
else if item5 is "Titre" then
return item2 & " • " & item1 & " • " & item3 & " • " & item4
else if item5 is "Sujet" then
return item3 & " • " & item1 & " • " & item2 & " • " & item4
else
return item4 & " • " & item1 & " • " & item2 & " • " & item3
end if
end getInfos
on getInfos2()
if item5 is "Auteur" then
return item1
else if item5 is "Titre" then
return item2
else if item5 is "Sujet" then
return item3
else
return item4
end if
end getInfos2
end script
end createCard

>>Ouvrir le script dans l'éditeur

DataBase (3/5)

on newCard()
set item1 to text returned of (display dialog "Auteur :" default answer "" with icon 1)
set item2 to text returned of (display dialog "Titre :" default answer "" with icon 1)
set item3 to text returned of (display dialog "Sujet :" default answer "" with icon 1)
set item4 to text returned of (display dialog "Edition :" default answer "" with icon 1)
set item5 to "Auteur" -- tri par defaut
set the end of allCards to createCard(item1, item2, item3, item4, item5)
end newCard

>>Ouvrir le script dans l'éditeur