Pages

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