Lorsque vous développez en javascript et concevez des feuilles de style CSS, vous pouvez être emmené à utiliser l’outil mis à disposition par Yahoo afin d’optimiser les fichiers et réduire leur taille : YUI Compressor.
Je vous propose de télécharger un outil réalisé en AppleScript qui permet de lancer YUI Compressor et traiter vos fichiers.
Installation
Le programme Java de YUI Compressor est à installer dans le dossier /usr/local/bin . Le script lance le programme nommé : yuicompressor-2.4.2.jar.
Si vous souhaitez mettre à jour le fichier ou changer le dossier d’installation de YUI Compressor, vous pouvez adapter le programme à votre convenance en ouvrant l’application pour éditer le script.
Principe de YUI Compressor launcher :
- Récupère les fichiers du Finder sélectionnés
- Vérifie que le fichier comporte l’extension JS (Javascript) ou
CSS (Cascading Style Sheet) - Exécute YUI Compressor et crée une nouvelle version du fichier
sous la forme : nom-min.js
(Finder Toolbar Script) – Contient le programme Applescript et les sources.
L’outil a été créé pour mon propre usage, il est donc fourni sans garantie.
Code source (applescript) :
tell application "Finder" set myFiles to selection set thisFolder to (target of front window) as Unicode text set thisFolder to POSIX path of thisFolder repeat with i from 1 to number of items in myFiles set file_name to name of item i in myFiles set file_ext to name extension of item i in myFiles set file_path to item i in myFiles as string if (file_ext = "js" or file_ext = "css") then -- Get the file name without extension set file_name_noext to name of item i in myFiles as string set file_name_noext to (the reverse of every character of file_name_noext) as string set x to the offset of "." in file_name_noext set file_name_noext to (text (x + 1) thru -1 of file_name_noext) as string set file_name_noext to (the reverse of every character of file_name_noext) as string # YUI Compressor if file_ext contains "js" then do shell script "java -jar /usr/local/bin/yuicompressor-2.4.2.jar " & "-o " & quoted form of thisFolder & file_name_noext & "-min.js " & quoted form of thisFolder & file_name else if file_ext contains "css" then do shell script "java -jar /usr/local/bin/yuicompressor-2.4.2.jar " & "-o " & quoted form of thisFolder & file_name_noext & "-min.css " & quoted form of thisFolder & file_name end if else #Uniquement des fichiers JS et CSS display dialog "Le fichier traité doit être un fichier Javascript ou CSS." with title "YUI Compressor" with icon 1 buttons {"OK"} default button {"OK"} end if end repeat end tell
Pour télécharger YUI Compressor, voici le lien sur le site de Yahoo Developer : http://developer.yahoo.com/yui/compressor/
If you use YUI compressor to optimize your Javascript and CSS files on Mac OSX. You can use this Finder toolbar script to launch the compressor and minimize your files. The program, made with applescript, open the selected files and create new one on the same folder with a different name (like name-min.js).
YUI compressor must be installed on the folder /usr/local/bin and the script search for yuicompressor-2.4.2.jar. If you have a different configuration, you can adapt the program itself.
![Agonia Studios [Blog]](http://www.agonia-studios.fr/blog/images/logo-weblog.png)











