Copy link to clipboard
Copied
Hey y'all!
I'm attempting to create a script to help return all of the file names of PDFs created by a user on a specific date. I'm running into some issues finding a way to return the owner's name. I couldn't find any related posts or any documentation online so I'm starting to think that this might not be possible. Let me know if you need any more information to take a crack at this!
Here is what I have:
*I left the folder line open so you can adjust it to use your own*
var folder = new Folder("C:\\Users\\Kernzy\\Downloads\\DailyTester"); // replace with the path to your folder
var files = folder.getFiles();
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file instanceof File) {
var owner = file.owner;
var created = file.created;
alert("File: " + file.name + "\nOwner: " + owner + "\nCreated: " + created);
}
}
Current Alert:
File: Tile.pdf
Owner: undefined
Created: Tue Mar 28 2023 10:13:19 GMT-0500
Goal Alert:
File: Tile.pdf
Owner: Kernzy
Created: Tue Mar 28 2023 10:13:19 GMT-0500
Copy link to clipboard
Copied
If it's not in the metadata where are you expecting to pull it from?
Copy link to clipboard
Copied
For this example I'm trying to pull the 'AD\krburns'
I was thinking the information might be available somewhere if I can find it here.
I'm able to pull the information via PowerShell, but I wasn't sure if there was a way to pull that same info with JavScript or ExtendScript directly.
Copy link to clipboard
Copied
file owner is not accessible to illustrator api, you could get it with vbs but if you already have a powershell script, then use that.
your jsx script would write a vbs file on the fly and run it via file.execute();
here's a vbs script that gets the file owner
https://www.vbsedit.com/scripts/security/ownership/scr_1386.asp
Copy link to clipboard
Copied
Hi @Kernzy, "owner" isn't a property of ExtendScript File object and there's no way to get it from native ExtendScript as far as I can see. However, maybe you can get it via PowerShell. See this thread. I'm a Mac user so I can't test. I assume you can get a result back from a PowerShell script? If not, you'll need to write it to a temporary text file and have ExtendScript read that file to get the result.
- Mark
Copy link to clipboard
Copied
I'm really close to solving this, but I'm caught up on executing a PowerShell Script from my ExtendScript.
Currently, I have the main ExtendScript that captures the date and the username of the files I want to open. When this information is captured I have a function that will write a new PowerShell script that can find all of the files from that desired day and by that user. The PowerShell script writes the file paths of those documents into a .txt file which is then passed back into the ExtendScript to be opened. The only issue is I have to run the PowerShell Script outside of Illustrator while the ExtendScript waits at on an alert to be clicked.
I've tried the link you sent @m1b, that method works in Photoshop, but not in Illustrator.
@CarlosCanto , I haven't tried your method yet because I've gotten so far already.
Anyone have any ideas?
I can share the script I have privately if needed.
Copy link to clipboard
Copied
what do you need help with? not having to rely on the alert window to continue executing the extendscript?
Copy link to clipboard
Copied
Preferably, I would like to find a way to run the PowerShell script from the ExtendScript. I won't be the end user for this script, so eliminating the need to leave Illustrator is preferred.
Here is the extendscript:
var employees = {
Admin1: "***insert your comp profile name here***",
};
getKeys(employees);
password();
function password() {
var popUp = new Window("dialog");
popUp.text = "Daily Art Fetch";
popUp.orientation = "column";
popUp.alignChildren = ["center","top"];
popUp.spacing = 10;
popUp.margins = 16;
var textGroup = popUp.add("group", undefined, {name: "textGroup"});
textGroup.orientation = "row";
textGroup.alignChildren = ["left","fill"];
textGroup.spacing = 10;
textGroup.margins = 0;
var textPan = textGroup.add("panel", undefined, undefined, {name: "textPan"});
textPan.text = "Password";
textPan.orientation = "column";
textPan.alignChildren = ["left","top"];
textPan.spacing = 10;
textPan.margins = 10;
var password = textPan.add('edittext {properties: {name: "password"}}');
password.preferredSize.width = 150;
password.active = true;
password.text = "layout2023";
var buttonGroup = popUp.add("group", undefined, {name: "buttonGroup"});
buttonGroup.orientation = "row";
buttonGroup.alignChildren = ["left","center"];
buttonGroup.spacing = 10;
buttonGroup.margins = 0;
var cancButton = buttonGroup.add("button", undefined, undefined, {name: "cancButton"});
cancButton.text = "Cancel";
cancButton.preferredSize.width = 75;
var enterButton = buttonGroup.add("button", undefined, undefined, {name: "enterButton"});
enterButton.text = "Enter";
enterButton.preferredSize.width = 75;
enterButton.onClick = function() {
if (password.text == "layout2023") {
popUp.close();
searchFiles();
} else {
alert("These are not the droids you are looking for")
popUp.close();
}
}
popUp.show();
}
function searchFiles() {
// Create a new dialog window
var dialog = new Window("dialog", "Excel Files");
// Add a panel to the dialog window
var panel = dialog.add("panel", undefined, "File Information");
panel.alignChildren = ["fill", "top"];
panel.margins = 20;
// Add a static text to the panel
var layoutArtistLabel = panel.add("statictext", undefined, "Layout Artist:");
layoutArtistLabel.preferredSize.width = 100;
// Add a dropdown list for month selection to the date group
var empList = panel.add("dropdownlist", undefined, undefined, {name: "Emp", items: keys});
empList.selection = 0;
// Add another static text to the panel
var dateLabel = panel.add("statictext", undefined, "Date:");
dateLabel.preferredSize.width = 100;
// Add a group to the panel for date input
var dateGroup = panel.add("group");
dateGroup.alignChildren = ["left", "center"];
// Add a dropdown list for month selection to the date group
var monthList = dateGroup.add("dropdownlist", undefined, ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]);
monthList.selection = 2;
// Add a dropdown list for day selection to the date group
var dayList = dateGroup.add("dropdownlist", undefined, ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]);
dayList.selection = 26;
// Add a dropdown list for year selection to the date group
var yearList = dateGroup.add("dropdownlist", undefined, ["2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030"]);
yearList.selection = 2;
// Add a group to the dialog window for buttons
var buttonGroup = dialog.add("group");
buttonGroup.alignChildren = ["center", "center"];
// Add a cancel button to the button group
var cancelButton = buttonGroup.add("button", undefined, "Cancel");
cancelButton.onClick = function() {
dialog.close();
};
// Add an ok button to the button group
var okButton = buttonGroup.add("button", undefined, "OK");
okButton.onClick = function() {
var layoutArtist = employees[empList.selection];
var month = monthList.selection.text;
var day = dayList.selection.text;
var year = yearList.selection.text;
var date = month + "/" + day + "/" + year;
dialog.close();
var logText = "$directory = '***\\YOUR\\DOCUMENT\\FILEPATH\\Here'\n$files = Get-ChildItem -Path $directory -Filter *.pdf | Where-Object {$_.LastWriteTime.date -eq '" + date + "' -and (Get-Acl $_.FullName).Owner -eq '" + employees[empList.selection] + "'}\nforeach ($file in $files) {\n$name = $file.FullName\n$owner = (Get-Acl $file.FullName).Owner\nAdd-Content -Path \"$HOME\\downloads\\PDFFileNames.txt\" -value $name\n}"
var filePath = "~/Downloads/DailyArtPS.ps1"
writeTask(filePath, logText);
alert("Please run the PoweShell script\nin your Downloads folder");
openDailyArt();
removefiles('DailyArtPS.ps1')
removefiles('PDFFileNames.txt')
};
// Show the dialog window
dialog.show();
}
function getKeys(arr) {
keys = [];
for (var k in arr) {
keys.push(k);
}
return keys;
}
function writeTask(filePath, logText) {
var file = new File(filePath);
file.open("w")
file.write(logText);
file.close();
}
function openDailyArt() {
// Define the file path to the text file containing the list of PDF file names
var filePath = '~/downloads/PDFFileNames.txt';
// Open the file
var file = File(filePath);
// Check if the file exists
if (file.exists) {
// Read the contents of the file
file.open('r');
var contents = file.read();
file.close();
// Split the contents into an array of lines
var lines = contents.split('\n');
// Loop through each line and open the corresponding file
for (var i = 0; i < lines.length - 1; i++) {
var pdfFile = File(lines[i].replace(/^\s+|\s+$/g, ''));
if (pdfFile.exists) {
app.open(pdfFile);
} else {
alert('File not found: ' + lines[i]);
}
}
}
}
function removefiles(sourceFileName) {
var sourceFolderPath = '~/Downloads/';
var sourceFilePath = sourceFolderPath + sourceFileName;
var sourceFile = new File(sourceFilePath);
if (sourceFile.exists) {
sourceFile.remove(sourceFilePath);
}
}
Line 3: Insert your 'owner name'/username for you computer. Ex 'AD\krburns' from the screenshot above
Line 123: the line where the PowerShell is written. You will need to replace that with a file path where you have PDF files if you are running it.
Copy link to clipboard
Copied
I haven't tried your script yet, but to answer your question. I wrote an additional BAT file to run the powerShell script.
so the jsx would trigger the bat file (batFile.execute()), then the bat file would trigger the powershell script
Copy link to clipboard
Copied
Do you have a snippet to show how you did this? I can not seem to figure it out!