├── .gitignore ├── Hilfslinien.jsx ├── Holidays.jsxinc ├── Progressor.jsxinc ├── README.de.md ├── README.md ├── Schriften.jsx ├── cal.jsx ├── dates.jsxinc ├── example.jsx ├── example.psd ├── holidays ├── germany-bavaria.hld └── usa.hld ├── printexport.jsx ├── util.jsxinc └── webexport.jsx /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | example-gen-* 3 | 4 | # Temporary files 5 | *~ 6 | *.swp 7 | 8 | # KDE 9 | .directory 10 | 11 | # Windows image file caches 12 | Thumbs.db 13 | 14 | # Folder config file 15 | Desktop.ini 16 | 17 | -------------------------------------------------------------------------------- /Hilfslinien.jsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Sript creates guide lines for borders 3 | * and at some ratios 4 | */ 5 | 6 | 7 | var 8 | VERTICAL = "Vrtc",/* | */ 9 | HORIZONTAL = "Hrzn",/* - */ 10 | PHI = -( (1-Math.sqrt(5))/2 ), 11 | ONE_MINUS_PHI = 1-PHI; 12 | 13 | function createGuide( offs,orientation ) { 14 | var id8 = charIDToTypeID( "Mk " ); 15 | var desc4 = new ActionDescriptor(); 16 | var id9 = charIDToTypeID( "Nw " ); 17 | var desc5 = new ActionDescriptor(); 18 | var id10 = charIDToTypeID( "Pstn" ); 19 | var id11 = charIDToTypeID( "#Rlt" ); 20 | desc5.putUnitDouble( id10, id11, offs.as("pt") ); 21 | var id12 = charIDToTypeID( "Ornt" ); 22 | var id13 = charIDToTypeID( "Ornt" ); 23 | var id14 = charIDToTypeID( orientation ); 24 | desc5.putEnumerated( id12, id13, id14 ); 25 | var id15 = charIDToTypeID( "Gd " ); 26 | desc4.putObject( id9, id15, desc5 ); 27 | executeAction( id8, desc4, DialogModes.NO ); 28 | } 29 | 30 | function createGuideFrame( size ) { 31 | var height=activeDocument.height; 32 | var width=activeDocument.width; 33 | 34 | createGuide( size,HORIZONTAL ); 35 | createGuide( size,VERTICAL ); 36 | createGuide( height-size,HORIZONTAL ); 37 | createGuide( width-size, VERTICAL ); 38 | } 39 | 40 | function createGuideMids( ) { 41 | var height=activeDocument.height; 42 | var width=activeDocument.width; 43 | createGuide( height/2,HORIZONTAL ); 44 | createGuide( width/2, VERTICAL ); 45 | } 46 | 47 | function createGuideGoldenRatio(border,v1,v2,h1,h2) { 48 | var height=activeDocument.height; 49 | var width=activeDocument.width; 50 | if(h2) createGuide( border + (height-2*border)*PHI,HORIZONTAL ); 51 | if(v2) createGuide( border + (width-2*border)*PHI, VERTICAL ); 52 | if(h1) createGuide( border + (height-2*border)*ONE_MINUS_PHI,HORIZONTAL ); 53 | if(v1) createGuide( border + (width-2*border)*ONE_MINUS_PHI, VERTICAL ); 54 | } 55 | 56 | var 57 | msgWindowTitle = localize({de:"Hilfslinen-Erstellung",en:"Create Guides"}), 58 | msgBorderPanel = localize({de:"Rand",en:"Margin"}), 59 | msgMidsPanel = localize({de:"Mitten",en:"Midlines"}), 60 | msgMidsCb = localize({de:"Mittellinien",en:"Midlines"}), 61 | msgGoldenRatTitle = localize({de:"Goldener Schnitt",en:"Golden Ratio"}), 62 | msgBuild = localize({de:"Erstellen",en:"Create"}), 63 | msgCancel = localize({de:"Abbrechen",en:"Cancel"}) 64 | ; 65 | 66 | var guidelinerResource = 67 | "dialog { \ 68 | alignChildren:['left', 'top'], \ 69 | text: '"+msgWindowTitle+"', \ 70 | borderPnl: Panel { text:'"+msgBorderPanel+"', orientation:'column',alignChildren:['left', 'top'],\ 71 | cb: Checkbox { \ 72 | text:'"+msgBorderPanel+"', value:false \ 73 | }, \ 74 | grp: Group { \ 75 | st: StaticText { text:'Abstand zum Rand:' }, \ 76 | et: EditText { characters:5, justify:'right',text:'1' } \ 77 | stmm: StaticText { text:'mm' }, \ 78 | } \ 79 | }, \ 80 | midsPnl: Panel { text:'"+msgMidsPanel+"', orientation:'column',\ 81 | cb: Checkbox { \ 82 | text:'"+msgMidsCb+"', value:false \ 83 | }, \ 84 | }, \ 85 | goldenRatioPnl: Panel { text:'"+msgGoldenRatTitle+"',orientation:'column',\ 86 | grp: Group { \ 87 | vertical1Cb: Checkbox { text:'|1', value:false}, \ 88 | vertical2Cb: Checkbox { text:'|2', value:false}, \ 89 | horizontal1Cb: Checkbox { text:'-1', value:false}, \ 90 | horizontal2Cb: Checkbox { text:'-2', value:false}, \ 91 | } \ 92 | }, \ 93 | btnGrp: Group { orientation:'row',alignment:'right', \ 94 | buildBtn: Button { text:'"+msgBuild+"', properties:{name:'ok'} }, \ 95 | cancelBtn: Button { text:'"+msgCancel+"', properties:{name:'cancel'} } \ 96 | } \ 97 | }"; 98 | 99 | var dlg = new Window(guidelinerResource); 100 | var returnValue = dlg.show() 101 | if(returnValue===1) { 102 | var border=UnitValue(0,"mm"); 103 | if(dlg.borderPnl.cb.value) { 104 | border=UnitValue(dlg.borderPnl.grp.et.text,"mm"); 105 | createGuideFrame(border); 106 | } 107 | if(dlg.midsPnl.cb.value) { 108 | createGuideMids(); 109 | } 110 | var g=dlg.goldenRatioPnl.grp; 111 | createGuideGoldenRatio( 112 | border, 113 | g.vertical1Cb.value, 114 | g.vertical2Cb.value, 115 | g.horizontal1Cb.value, 116 | g.horizontal2Cb.value 117 | ); 118 | } else { 119 | // aborted, returnValue===2 120 | } 121 | 122 | -------------------------------------------------------------------------------- /Holidays.jsxinc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/Holidays.jsxinc -------------------------------------------------------------------------------- /Progressor.jsxinc: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a Photoshop UI-Component to display neat progress bars 3 | */ 4 | 5 | var Progressor = function(names){ 6 | var _ = localize; // shortcut for localization function 7 | 8 | // Localized messages (de,en) 9 | var msg={ 10 | cancel:{de:"Abbrechen",en:"Cancel"}, 11 | cancelRequested:{de:"Abbrechen angefragt. ",en:'Cancel requested. '}, 12 | initializing:{de:"Initialisierung...",en:'Initializing...'}, 13 | // The localize() functions inserts values for us too: 14 | progress:{de:"Bearbeite %1 von %2...",en:"Processing %1 of %2..."}, 15 | }; 16 | 17 | // If the user has clicked the cancel button yet 18 | var isCancelRequested = false; 19 | 20 | // Create a window first 21 | var dlg = new Window('window', _(names)/*window name*/); 22 | dlg.mainGroup = dlg.add('group'); 23 | // Align groups below eatch other 24 | dlg.mainGroup.orientation = "column"; 25 | dlg.mainGroup.alignChildren = "right"; 26 | 27 | // Add groups 28 | dlg.progressGroup = dlg.mainGroup.add('group'); 29 | dlg.statusGroup = dlg.mainGroup.add('group'); 30 | dlg.btnGroup = dlg.mainGroup.add('group'); 31 | 32 | // Add UI elements 33 | 34 | // Progress bar 35 | dlg.progressbar = dlg.progressGroup.add('progressbar'); 36 | dlg.progressbar.preferredSize = [400,20]; // make 400px wide 37 | 38 | // Status text 39 | dlg.stautsText = dlg.statusGroup.add('statictext',undefined,_(msg.initializing)); 40 | dlg.stautsText.preferredSize = [400,20]; // make 400px wide too 41 | 42 | // Cancel Button 43 | dlg.cancelBtn = dlg.btnGroup.add('button',undefined,_(msg.cancel)); 44 | dlg.cancelBtn.onClick=function(){ // cancel event handler 45 | isCancelRequested=true; 46 | dlg.stautsText.text = _(msg.cancelRequested); 47 | } 48 | 49 | // Show the window 50 | dlg.show(); 51 | 52 | // export methods for outside control 53 | var self = { 54 | // Indicate progression of the script 55 | progress: function(i,of) { 56 | dlg.progressbar.value=Math.round(100*i/of); 57 | dlg.stautsText.text=_(msg.progress,i+1,of); 58 | dlg.update(); 59 | }, 60 | // Call at the end of the script 61 | done: function() { 62 | dlg.close(); 63 | }, 64 | // Poll while exectuing, abort when true 65 | isCancelRequested: function(){ 66 | return isCancelRequested; 67 | } 68 | }; 69 | return self; 70 | }; 71 | -------------------------------------------------------------------------------- /README.de.md: -------------------------------------------------------------------------------- 1 | Photoshop-Javascript-Tools 2 | ========================== 3 | 4 | Version 0.9.2 5 | 6 | [News](http://bernhardhaeussner.de/blog/tags/Photoshop "News") 7 | 8 | Inhalt 9 | ------ 10 | 11 | Die Photoshop Javascript Tools enthalten einige nützliche Scripten lauffähig in 12 | Adobe Photoshop CS3. Unterstützt werden Deutsch und English. 13 | 14 | Für Enbenutzer: (*) 15 | 16 | * Hilfslinien.jsx: Erstellung von Hilfslinien als Mittellinien und im Goldenen Schnitt 17 | * Schriften.jsx: Schriftarten-Namen anzeigen und ändern im JS-Format 18 | 19 | Für Javascript-Entwickler: 20 | 21 | * example.jsx: Beispielhaftes Stapelverarbeitungs-Script, um Texte aus JSON-Daten einzufügen 22 | * Progressor.jsxinc: Ein Fortschrittsbalken-UI 23 | * util.jsxinc: Nützliche Funktionen zum Umbennenen von Dateien und Formatieren von Zahlen 24 | * dates.jsxinc: Datumsfunktionen 25 | * Holidays.jsxinc: Sich jährlich wiederholende Termine berechen aus .hld-Dateien 26 | * cal.jsx: Beispiel, um einen hübschen Kalender mit Feiertagen zu erstellen 27 | * webexport.jsx: Beispiel, um viele Bilder als verkleinertes JPEG zu exportieren 28 | * printexport.jsx: Ähnlich, prüft jedoch auf 300dpi und ein Farbprofil 29 | 30 | Installation 31 | ------------ 32 | 33 | Zum Installieren müssen die Dateien unter (*) in den Ordner 34 | `Adobe Photoshop CS3/Vorgaben/Skripten/` bzw. 35 | `Adobe Photoshop CS3/Presets/Scripts/` kopiert werden. 36 | 37 | Dnn muss die Umgebungsvariable `JSINCLUDE` auf den Pfad dieses Ordners 38 | eingestellt werden, also z.B. `/c/Programme/Photoshop-Javascript-Tools/` 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Photoshop-Javascript-Tools 2 | ========================== 3 | 4 | Version 0.9.2 5 | 6 | [News](http://bernhardhaeussner.de/blog/tags/Photoshop "News") 7 | 8 | Contents 9 | -------- 10 | 11 | The Photoshop Javascript Tools include some handy scripts tested in 12 | Adobe Photoshop CS3. Supported languages are German and English. 13 | 14 | For end users: (*) 15 | 16 | * Hilfslinien.jsx: Create guide lines for margin, midlines and golden ratio 17 | * Schriften.jsx: View and change font names as used in JS 18 | 19 | For Javascript developers: 20 | 21 | * example.jsx: Simple template batch processing script for including text from JSON data 22 | * Progressor.jsxinc: A progress bar UI 23 | * util.jsxinc: Utility functions for file renaming and number formating 24 | * dates.jsxinc: Date utilities 25 | * Holidays.jsxinc: Calculate repeating days for a year based on .hld files 26 | * cal.jsx: Example for creating a neat calendar with holidays 27 | * webexport.jsx: Example for batch exporting to resized JPEGs 28 | * printexport.jsx: Similar, but checking for 300dpi and color profile too 29 | 30 | Installing 31 | ---------- 32 | 33 | To install simply copy the files listed at (*) into the directoy 34 | `Adobe Photoshop CS3/Presets/Scripts/` or 35 | `Adobe Photoshop CS3/Vorgaben/Skripten/`. 36 | 37 | Then set your `JSINCLUDE` enviroment variable to the path of this 38 | directory, e.g. `/c/Program Files/Photoshop-Javascript-Tools/` 39 | 40 | Progressor.jsxinc: A progress bar UI 41 | ------------------------------------ 42 | 43 | ![image](https://f.cloud.github.com/assets/639509/1323014/007bedba-345e-11e3-8cf6-b6b92cc1f223.png) 44 | 45 | The Progressor allows you to watch your script proceed. You can use it 46 | in your code like this: 47 | 48 | #include Progressor.jsxinc 49 | 50 | for (var i = 0; i < data.length && !progressor.isCancelRequested(); i++) { 51 | progressor.progress(i,data.length); // update progress bar 52 | 53 | // ... 54 | } 55 | 56 | progressor.done(); 57 | 58 | If you don't have a simple loop like this, you can use a custom way to call `progress`. 59 | -------------------------------------------------------------------------------- /Schriften.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/Schriften.jsx -------------------------------------------------------------------------------- /cal.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a calendar Javascript for Adobe Photoshop CS3 3 | */ 4 | 5 | // Include the utilities 6 | #include util.jsxinc 7 | #include dates.jsxinc 8 | #include Progressor.jsxinc 9 | #include Holidays.jsxinc 10 | 11 | // Set a script name 12 | var scriptName={en:"calendar script",de:"Kalender-Skript"}; 13 | 14 | // Saving options 15 | var psdOpts = new PhotoshopSaveOptions(); 16 | 17 | // Porgress bar widget 18 | var progressor = Progressor(scriptName); 19 | 20 | var lineColor = new SolidColor(); 21 | lineColor.rgb.hexValue="dddddd"; 22 | 23 | var kwColor = lineColor; 24 | 25 | var normalDaytextColor = new SolidColor(); 26 | normalDaytextColor.rgb.hexValue="182b43"; 27 | 28 | var saturdayDaytextColor = new SolidColor(); 29 | saturdayDaytextColor.rgb.hexValue="5d718b"; 30 | 31 | var holidayDaytextColor = new SolidColor(); 32 | holidayDaytextColor.rgb.hexValue="839ab7"; 33 | 34 | // sans-serif: 35 | //var monthNameFont="MyriadPro-Light"; 36 | //var dayNameFont="MyriadPro-Regular"; 37 | 38 | // serif: 39 | var monthNameFont="GaramondPremrPro-Med"; 40 | var dayNameFont="GaramondPremrPro"; 41 | 42 | var holidays=createHolidaysFromRegion( 43 | "germany-bavaria"); 44 | //"usa"); 45 | 46 | var yearLayername={en:"calendar, year %1",de:"Kalender, Jahr %1"}; 47 | var monthLayername={en:"month %1",de:"Monat %1"}; 48 | 49 | function mm(x) {return new UnitValue(x,"mm");} 50 | function pxc(x) {x.baseUnit=UnitValue(1/300,"in"); return x.as("px");} 51 | 52 | if (app.documents.length > 0) { // check if file is opened 53 | 54 | var year=2012; 55 | 56 | var supergroup=activeDocument.layerSets.add(); 57 | supergroup.name=localize(yearLayername,year); 58 | 59 | var premonth=-3; 60 | var prekw=-3; 61 | var group; 62 | for( 63 | var i=1, 64 | d=new Date(year,0,i); 65 | d.getFullYear()==year && !progressor.isCancelRequested(); 66 | d=new Date(year,0,++i)) { 67 | 68 | 69 | if(d.getMonth()!=premonth) { 70 | //if(premonth!=-3) break; // only 1 month 71 | group=supergroup.layerSets.add(); 72 | group.name=localize(monthLayername,(1+d.getMonth())); 73 | //group.visible=false; 74 | 75 | var monthName = group.artLayers.add(); 76 | monthName.kind=LayerKind.TEXT; 77 | monthName.name="month "+(1+d.getMonth())+" name"; 78 | monthName.textItem.color=normalDaytextColor; 79 | monthName.textItem.size=24; 80 | monthName.textItem.font=monthNameFont; 81 | monthName.textItem.kind=TextType.POINTTEXT // PARAGRAPHTEXT 82 | monthName.textItem.justification = Justification.RIGHT; 83 | monthName.textItem.contents=monthNames[d.getMonth()]+" "+d.getFullYear(); 84 | monthName.rotate(-90); 85 | monthName.textItem.position=[97.7,17]; 86 | 87 | premonth=d.getMonth(); 88 | } 89 | 90 | var x=mm(105),y=mm(17+d.getDate()*4); 91 | 92 | var dayGroup=group.layerSets.add(); 93 | dayGroup.name=d.toLocaleString(); 94 | 95 | var dayLine=dayGroup.artLayers.add(); 96 | dayLine.name="line "+d.getDate(); 97 | var yL=y+mm(0.65); 98 | var xL=x-mm(3.5); 99 | activeDocument.selection.select([[pxc(xL),pxc(yL)],[pxc(xL),pxc(yL+mm(0.2))],[pxc(xL+mm(40)),pxc(yL+mm(0.2))],[pxc(xL+mm(40)),pxc(yL)]]); 100 | activeDocument.selection.fill(lineColor); 101 | activeDocument.selection.deselect(); 102 | 103 | var textColor=normalDaytextColor; 104 | if(d.getDay()==6/*sat*/) textColor=saturdayDaytextColor; 105 | if(d.getDay()==0/*sun*/) textColor=holidayDaytextColor; 106 | 107 | var myHoliday=holidays.getDaysForDate(d); 108 | var myHolidayString=''; 109 | for(var hd=0;myHoliday && hd 0) { // check if file is opened 37 | for (var dataI = 0; dataI < data.length && !progressor.isCancelRequested(); dataI++) { 38 | progressor.progress(dataI,data.length); // update progress bar 39 | 40 | var textGroup = activeDocument.layerSets[0]; // find our layer group 41 | 42 | // Substitute new text 43 | textGroup.artLayers[0].textItem.contents="Hello, "+data[dataI].name+"!"; 44 | if(data[dataI].comment) { 45 | textGroup.artLayers[1].textItem.contents=data[dataI].comment; 46 | } else { 47 | textGroup.artLayers[1].textItem.contents="Welcome to Photoshop scripting."; 48 | } 49 | 50 | // Save copy and export 51 | activeDocument.saveAs(buildFilename(activeDocument.fullName,data[dataI].name,dataI,'psd'),psdOpts,true); 52 | activeDocument.saveAs(buildFilename(activeDocument.fullName,data[dataI].name,dataI,'jpg'),jpgOpts,true); 53 | fileI++; 54 | } 55 | } 56 | progressor.done(); 57 | -------------------------------------------------------------------------------- /example.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/example.psd -------------------------------------------------------------------------------- /holidays/germany-bavaria.hld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/holidays/germany-bavaria.hld -------------------------------------------------------------------------------- /holidays/usa.hld: -------------------------------------------------------------------------------- 1 | # List of US holidays, I guess 2 | 3 | * fixed 01/01 New Year's Day 4 | * dowMon 31-01 Martin Luther King Day 5 | * dowMon 31-02 Washington's Birthday 6 | * dowMoL 11-05 Memorial Day 7 | * fixed 04/07 Independence Day 8 | * dowMon 11-09 Labor Day 9 | * dowMon 21-10 Columbus Day 10 | * fixed 11/11 Veterans Day 11 | * dowMon 44-11 Thanksgiving Day 12 | * fixed 25/12 Christmas Day 13 | -------------------------------------------------------------------------------- /printexport.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/printexport.jsx -------------------------------------------------------------------------------- /util.jsxinc: -------------------------------------------------------------------------------- 1 | 2 | function buildFilename(origname,name,index,suffix) { 3 | var filename = extractFilestart(origname) 4 | if(index!==undefined) filename+="-gen-"+zeropad(index) 5 | if(name!==undefined) filename+="-"+filesc(name) 6 | if(suffix!==undefined) filename+="."+suffix 7 | return new File(filename); 8 | } 9 | 10 | function extractFilestart(origname) { 11 | return origname.path+"/"+removeFileExtension(origname.name); 12 | } 13 | 14 | function filesc(str) { 15 | return (str+'') 16 | .toLowerCase() 17 | .replace('�','oe') 18 | .replace('�','ae') 19 | .replace('�','ue') 20 | .replace('�','ss') 21 | .replace(/[^0-9A-Za-z]+/g,'-') 22 | .replace(/^-|-$/g,''); 23 | } 24 | 25 | function zeropad(n,anz) { 26 | anz=anz||5; 27 | var digitAnz=n==0?1:Math.floor(Math.log(n)/Math.log(10))+1; 28 | return new Array(anz-digitAnz+1).join('0')+n; 29 | } 30 | 31 | function removeFileExtension(filename) { 32 | // http://stackoverflow.com/questions/1818310/regular-expression-to-remove-a-files-extension 33 | return filename.substr(0, filename.lastIndexOf('.')) || filename; 34 | } -------------------------------------------------------------------------------- /webexport.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bxt/Photoshop-Javascript-Tools/01aa2779eb5b2fb2332b17943a9c4e2b93292ef8/webexport.jsx --------------------------------------------------------------------------------