Created
June 26, 2018 03:50
-
-
Save NimaiMalle/4e793044357b796814534d8ddb8a7683 to your computer and use it in GitHub Desktop.
Add filename as text in a Photoshop document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this script is a variation of the script addTimeStamp.js that is installed with PH7 | |
if ( documents.length > 0 ) | |
{ | |
var originalDialogMode = app.displayDialogs; | |
app.displayDialogs = DialogModes.ERROR; | |
var originalRulerUnits = preferences.rulerUnits; | |
preferences.rulerUnits = Units.PIXELS; | |
try | |
{ | |
var docRef = activeDocument; | |
// Now create a text layer at the front | |
var myLayerRef = docRef.artLayers.add(); | |
myLayerRef.kind = LayerKind.TEXT; | |
myLayerRef.name = "Filename"; | |
var myTextRef = myLayerRef.textItem; | |
// strip the extension off | |
var fileNameNoExtension = docRef.name; | |
fileNameNoExtension = fileNameNoExtension.split( "." ); | |
if ( fileNameNoExtension.length > 1 ) { | |
fileNameNoExtension.length--; | |
} | |
fileNameNoExtension = fileNameNoExtension.join("."); | |
myTextRef.contents = fileNameNoExtension; | |
// off set the text to be in the middle | |
myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 ); | |
myTextRef.size = 20; | |
} | |
catch( e ) | |
{ | |
// An error occurred. Restore ruler units, then propagate the error back | |
// to the user | |
preferences.rulerUnits = originalRulerUnits; | |
app.displayDialogs = originalDialogMode; | |
throw e; | |
} | |
// Everything went Ok. Restore ruler units | |
preferences.rulerUnits = originalRulerUnits; | |
app.displayDialogs = originalDialogMode; | |
} | |
else | |
{ | |
alert( "You must have a document open to add the filename!" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I came across your file regarding add a file name as I needed this script for my photography editing.
Looking at the file, how can I change the default colour from black to white and realign the code to top right.
Kind regards
Gary