Why won't my script work on all files in the folder?
Hi, below is a script I hobbled together from various sources using the search function on this forum. It is supposed to change hyphens to en-dashes in a ai files in a folder. However, when I run it, it only works on one file. After it makes the change and closes the first file, it stops. Can anyone help me troubleshoot and fix the problem?
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
sourceFolder = Folder.selectDialog;
if ( sourceFolder != null )
files = new Array();
fileType = "*.ai";
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
sourceDoc = app.open(files[i]); // returns the document object
var active_doc = app.activeDocument;
var search_string = '-';
var replace_string = "\u2013";
var text_frames = active_doc.textFrames;
if (text_frames.length > 0)
for (var i = 0 ; i < text_frames.length; i++)
var this_text_frame = text_frames[i];
var new_string = this_text_frame.contents.replace(search_string, replace_string);
if (new_string != this_text_frame.contents)
this_text_frame.contents = new_string;
sourceDoc.save();
sourceDoc.close();
no easy way as you may wish, but not as difficult either. For eps files, you have to use SaveAs() method,
if ai - do save
if eps - do saveAs
here's a sample from the Documentation, or search the forum for other samples
// Exports current document to destFile as an EPS file with specified
// options, destFile contains the full path including the file name
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc;
if ( app.documents.length == 0 )
saveDoc = app.documents.add();
else
saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.cmykPostScript = true;
saveOpts.embedAllFonts = true;
saveDoc.saveAs( newFile, saveOpts );
Similar Messages
-
I have been searching high and low for this one. I have a vbscript that can successfully perform the function if one file is listed. It does a Wscript.echo on the results and if I run this via command using cscript, I can output to a text file
that way. However, I cannot seem to get it to work properly if I want it to search ALL the files in the folder. At one point, I was able to have it create the output file and appear as if it worked, but it never showed any results when the script
was executed and folder was scanned. So I am going back to the drawing board and starting from the beginning.
I also have a txt file that contains the list of string text entries I would like it to search for. Just for testing, I placed 4 lines of sample text and one single matching text in various target files and nothing comes back. The current script
I use for each file has been executed with a few hundred string text lines I want it to search against to well over one thousand. It might take awhile, but it works every time. The purpose is to let this run against various log files in a folder and
let it search. There is no deleting, moving, changing of either the target folder/files to run against, nor of the file that contains the strings to search for. It is a search (read) only function, going thru the entire contents of the folder and
when done, performs the loop function and onto the next file to repeat the process until all files are searched. When completed, instead of running a cscript to execute the script and outputting the results to text, I am trying to create that as part
of the overall script. Saving yet another step for me to do.
My current script is set to append to the same results file and will echo [name of file I am searching]: No errors found. Otherwise, the
output shows the filename and the string text that matched. Because the results append to it, I can only run the script against each file separately or create individual output names. I would rather not do that if I could include it all in one.
This would also free me from babysitting it and running each file script separately upon the other's completion. I can continue with my job and come back later and view the completed report all in one. So
if I could perform this on an entire folder, then I would want the entries to include the filename, the line number that the match occurred on in that file and the string text that was matched (each occurrence). I don't want the entire line to be listed
where the error was, just the match itself.
Example: (In the event this doesn't display correctly below, each match, it's corresponding filename and line number all go together on the same line. It somehow posted the example jumbled when I listed it)
File1.txt Line 54
Job terminated unexpectedly
File1.txt Line 58 Process not completed
File1.txt
Line 101 User input not provided
File1.txt
Line 105 Process not completed
File2.txt
No errors found
File3.txt
Line 35 No tape media found
File3.txt
Line 156 Bad surface media
File3.txt Line 188
Process terminated
Those are just random fake examples for this post.
This allows me to perform analysis on a set of files for various projects I am doing. Later on, when the entire search is completed, I can go back to the results file and look and see what files had items I wish to follow up on. Therefore, the
line number that each match was found on will allow me to see the big picture of what was going on when the entry was logged.
I actually import the results file into a spreadsheet, where further information is stored regarding each individual text string I am using. Very useful.
If you know how I can successfully achieve this in one script, please share. I have seen plenty of posts out there where people have requested all different aspects of it, but I have yet to see it all put together in one and work successfully.
Thanks for helping.I'm sorry. I was so consumed in locating the issue that I completely overlooked posting what exactly I was needing help with. I did have one created, but I came across one that seemed more organized than what I originally created. Later
on I would learn that I had an error in log location on my original script and therefore thought it wasn't working properly. Now that I am thinking that I am pretty close to achieving what I want with this one, I am just going to stick with it.
However, I could still use help on it. I am not sure what I did not set correctly or perhaps overlooking as a typing error that my very last line of this throws an "Expected Statement" error. If I end with End, then it still gives same
results.
So to give credit where I located this:
http://vbscriptwmi.uw.hu/ch12lev1sec7.html
I then adjusted it for what I was doing.
What this does does is it searches thru log files in a directory you specify when prompted. It looks for words that are contained in another file; objFile2, and outputs the results of all matching words in each of those log files to another file: errors.log
Once all files are scanned to the end, the objects are closed and then a message is echoed letting you know (whether there errors found or not), so you know the script has been completed.
What I had hoped to achieve was an output to the errors.log (when matches were found) the file name, the line number that match was located on in that file and what was the actual string text (not the whole line) that matched. That way, I can go directly
to each instance for particular events if further analysis is needed later on.
So I could use help on what statement should I be closing this with. What event, events or error did I overlook that I keep getting prompted for that. Any help would be appreciated.
Option Explicit
'Prompt user for the log file they want to search
Dim varLogPath
varLogPath = InputBox("Enter the complete path of the logs folder.")
'Create filesystem object
Dim oFSO
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
'Creates the output file that will contain errors found during search
Dim oTSOut
Set oTSOut = oFSO.CreateTextFile("c:\Scripts\errors.log")
'Loop through each file in the folder
Dim oFile, varFoundNone
VarFoundNone = True
For Each oFile In oFSO.GetFolder(varLogPath).Files
'Verifies files scanned are log files
If LCase(Right(oFile.Name,3)) = "log" Then
'Open the log file
Dim oTS
oTS = oFSO.OpenTextFile(oFile.Path)
'Sets the file log that contains error list to look for
Dim oFile2
Set oFile2 = oFSO.OpenTextFile("c:\Scripts\livescan\lserrors.txt", ForReading)
'Begin reading each line of the textstream
Dim varLine
Do Until oTS.AtEndOfStream
varLine = oTS.ReadLine
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
Dim colMatches, strName, strText
Do Until oErrors.AtEndOfStream
strName = oFile2.ReadLine
objRegEx.Pattern = ".{0,}" & strName & ".{0,}\n"
Set colMatches = objRegEx.Execute(varLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strText = strText & strMatch.Value
WScript.Echo "Errors found."
oTSOut.WriteLine oFile.Name, varLine.Line, varLine
VarFoundNone = False
Next
End If
Loop
oTS.Close
oFile2.Close
oTSOut.Close
Exit Do
If VarFoundNone = True Then
WScript.Echo "No errors found."
Else
WScript.Echo "Errors found. Check logfile for more info."
End If
End if -
Script to set all files in a folder to "Read and Write" permissions? Please
In advance my most abject apologies for posting such a simple question. I couldn't script my way out of a paper bag, and searching and googling have failed, no doubt because I don't even have the proper keywords. :-/
The script I need is so simple that it most likely exists somewhere already. Whenever I copy image files from a DVD-ROM or CD-ROM burned on a Windows laptop to my desktop Mac, the files and folders therein are "Read Only" on my Mac. If there are many files in the folder, it's very easy to Select All and do a Get Info on multiple items, so I can rectify the situation by changing the whole set in a single step. But if I have ten files or less in a folder, each file opens an Info dialog box and that can become very tedious when I have scores of folders with nine or so files in each.
Any guidance will be much appreciated.
Message was edited by: Ramón G CastañedaYou can attach a folder action to your destination folder, for example:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on adding folder items to ThisFolder after receiving AddedItems
repeat with AnItem in AddedItems
tell application "Finder" to set owner privileges of AnItem to read write
-- tell application "Finder" to set everyones privileges of AnItem to read write
end repeat
end adding folder items to
</pre>
... but you can also use the Inspector (option-command-i) to get a single info window for multiple items. -
Why won't preview let me delete all files (instead of all but one)
In all OSX versions up to snow leopard in preview there was the option to select all open items and move the files to the trash. For some reason unknown to me, in 10.8.5 mountain lion that option no longer exists. Now preview lets me delete all files except one. If you have 2 images open you can move 1 to the trash. If you have 99 open you can move 98 to trash and if you have 1 open, you cannot move it to trash. Is there some code available where I can undo this restriction?
Do you also have them on another computer, iPad or iPhone, IF you do then it may be syncing them back
-
Why won't my AppleTV work at all?
I think this TV might not be compatible. So I hooked everything up, and it doesn't "see" my network, which is a Time Warner Cable connection, NOT wireless. Is there a reason why it wouldn't work with a cable internet connection? Do I have to do anything more than turn it on to find that network? Not only does this not work, but homesharing doesn't either. Do you have to have the network connection before anything else will work? When I move through the options on the AppleTV menu, it doesn't give me any other option but to hook to a wireless network, but I don't have a wireless network. When I try to do homesharing, I put in my apple ID and password on my iTunes, which works (or seems to), and then when I try to put my login and password in on AppleTV, everytime I hit "submit" it brings me back to the original login screen. What the $&#&! is going on? Anyone want to help?
Info:
Computer: 2011 2.5 GHz i5 Intel Core iMac running OS 10.75.
TV: Insignia (BestBuy's brand) 39" model #NS-39L240A13
Thanks.sounds like your issue is how you connect your ethernet
if your router does not have a switch for several ethernet devices on the same LAN to speak with the internet and eachother it will not work -
Why won't LR5.7 let me add files in a folder to its catalog?
I accidentally imported files from an SD card into two different folders. Lightroom made me aware of this when I tried to copy them from folder A to the 'correct' folder B, by saying that they were already present in the destination folder.
The stats for folder B show only 10 pictures, not the 277 I tried to copy from foler A. I don't know how to persuade LR to show the 277 files, which it says are in folder B. File explorer confirms that the files are in both folders.
I've tried synchronising Folder B. LR says that it doesn't contain any files that aren't already in my catalog.
Any ideas what is going on and how I can make LR show these photos?
Thanks in advance,
SteveLightroom is not a file browser. If it thinks the photos are in folder A, you need to tell Lightroom that the photos are really in folder B. This is not a copy or a move. This is a "re-connect".
Here are instructions: Adobe Lightroom - Find moved or missing files and folders -
Why won't music match work with my Sonos system now?
I updated my iTunes to music match, because I added a new computer for my wife and she wanted easy access the music library. I used the music match and the iCloud to make it easier to get the music on the new computer. It was fairly simple to set it up, however, when I installed the sonos controller on the new computer, it couldn't find the music library. Why won't my sonos work, when I can see the music on iTunes in its library.
Maybe the speakers are not compatible with your computer. Contact the manufacturer.
You can try Resetting your Mac's PRAM and NVRAM to see if that resolves the issue. -
Add all files of one folder to aperture by running a script
HI,
i have a question:
I will make my Aperture Tethered more easy (with my Canon eos 30D) i have coded a script / folder action to do this but: this folder action does not import all pictures (wy ever, i think that the files coming in to fast were not recognized).
Now i will code a script which will include all files of a folder to aperture when it is run.
i will give it a try, and the import does function, but, i don't know how i can tell the script which files it should import (with a folder action its easy, with this line:
on adding folder items to this_folder after receiving these_items
but how to do this without the "on adding folder items" cause that does not happen in the case i will use it.
i'm looking forward to anthers:D
Best Regards
Christophyes i tryed this application, and there was the same problem as with my one (i have programmed my based on this application)
but both had the same problem they open on imageadd, but if i take more images in seconds (i think the script is still running => it can't recognize new images) it does not recognize the newly taken images.
and i hope some script that imports all images in the folder will solve the problem.
the more ore less only problem is to tell the application which images to import (like: on run import ALL files) -
How to move all files to the top level folder?
I want to move all files within a particular folder -- and all files in all sub folders -- to the top level. i.e. I want to collapse the folder structure to just one folder. Assume that there are no files with the same name.
*Method 1*
My first thought was to use Find:
1. Limit Find to the particular folder.
2. Find all files in the folder with Size > 0.
3. Switch to List view. All files are listed.
4. Select all files and drag to the top folder
5. Delete all sub folders manually.
Problem: Pages files are not found, and maybe others aren't.
This is a simple method and I'd like to stick with it.
*QUES 1*
What condition should I set within Find so that I can be guaranteed of finding all files?
*Method 2*
It was suggested in another thread that I use Terminal to move all files to the top level, but I couldn't get it to work. And there was a problem with files that consist of bundles.
*QUES 2*
What is the easiest way to consolidate all files within a folder to the top level -- assume no duplicate names -- and at the same time remove all sub folders?
Message was edited by: Guy BurnsThanks for the suggestion of EasyFind.
To find all files in a certain folder I typed in *[a-z 0-9] as a Boolean search (this thread won't let me post the exact characters required by EasyFind). That should cover every file I've ever named. EasyFind came back with "11719found/12316done".
Any idea what the missing 500 files would be? I'm hoping they are files that I don't need to know about (invisible files, system files and so on).
Message was edited by: Guy Burns -
Why won't my iMessage work with only one contact in my phone all my other iMessages send and they just got an iphone but all their iMessages are sending also. I've tried restarting my phone, deleting messages, contact, restarting network
Hello Jesslb23,
Thanks for using Apple Support Communities.
For more information on this, take a look at:
iOS: Troubleshooting Messages
http://support.apple.com/kb/ts2755
To resolve issues with sending and receiving iMessages, follow these steps first
Check iMessage system status for current service issues.
Go to Settings > Messages > Send & Receive and make sure that you have registered iMessage with your phone number or Apple ID and that you have selected iMessage for use. Learn more about troubleshooting iMessage registration if the phone number or Apple ID isn't available for use.
Open Safari and navigate to www.apple.com to verify data connectivity. Learn more about troubleshootingcellular data or a Wi-Fi connection if a data connection isn't available.
iMessage over cellular data might not be available while on a call. Only 3G and faster GSM networks support simultaneous data and voice calls. Learn more about which network your phone supports. Go to Settings > Wi-Fi and turn Wi-Fi on to use iMessage while on a call if your network doesn't support simultaneous data and voice calls.
Restart your device.
Tap Settings > General > Reset > Reset Network Settings on your iPhone.
If you are still unable to send or receive an iMessage, follow these steps
Make sure that the contact trying to message you isn't blocked in Settings > Messages > Blocked.
Verify that the contact you are attempting to send a message to is registered with iMessage.
If the issue occurs with a specific contact or contacts, back up or forward important messages and delete your current messaging threads with the contact. Create a new message to the contact and try again.
If the issue occurs with a specific contact or contacts, delete and re-create the contact in the Contacts application. Create a new message to the newly created contact and try again.
Back up and restore your device as new.
Best of luck,
Mario -
Why won't my email work on my new iphone 4. I have input all info but can't wsend or receive?
Hey briannagrace96,
Welcome to Apple Support Communities! I'd check out the following article, it looks like it applies to your situation:
iPod: Appears in Windows but not in iTunes
http://support.apple.com/kb/ts1363
You'll want to go through the following troubleshooting steps, and for more detail on each step follow the link to the article above:
Try the iPod troubleshooting assistant:
If you have not already done so, try the steps in the iPod Troubleshooting Assistant (choose your iPod model from the list).
If the issue remains after following your iPod's troubleshooting assistant, follow the steps below to continue troubleshooting your issue.
Restart the iPod Service
Restart the Apple Mobile Device Service
Empty your Temp directory and restart
Verify that the Apple Mobile Device USB Driver is installed
Change your iPod's drive letter
Remove and reinstall iTunes
Disable conflicting System Services and Startup Items
Update, Reconfigure, Disable, or Remove Security Software
Deleting damaged or incorrect registry keys
Take care,
David -
HT201398 Why won't podcast app work on iPhone 5 after ios 8.1.3 update?
Why won't podcast app work on iPhone 5 after ios 8.1.3 update?
I've restarted the phone and itunes several times, have uninstalled and reinstalled the app on the phone and itunes separately, and it still just shows 'Installing" under the greyed out app.I have the same problem with an iPhone 5s. All podcast fail to work on the phone since updating to iOS 8.1.3. What is going on? Is Apple taking this problem serious?
-
I am trying to use Find My Friends and I have been through troubleshooting 3 times. Why won't my location work? Everything is on but the 2nd screen in Find My Friends is grayed out, whereas my other family members 2nd screens are active? I have an iPhone 6 Plus, latest ios8, and yes my location says it is being shared, but it is not.
Pyralus wrote:
I decided to try and boot from the Tiger discs, but when I did, all I got was a screen that looked like a blizzard of pixels.
The firmware was likely changed and it's not compatible anymore or the disk is bad.
I was able to boot using the Snow Leopard disc from both my new MBP and my girlfriends MB, but both said that OS X could not be installed on this computer, and I couldn't even use the disc utility to wipe the drive.
Those disks don't have the hardware drivers your machine needs.
Your going to need to get a Snow Leopard retail install disk from Amazon/elsewhere.
Do I need to have a serial number to reinstall OS X?
Thankfully No. -
Why won't my I-Phone 4 all of a sudden not let me send picture messges? It keeps coming back as unsent with the exclamation mark.
Settings > Messages > MMS messaging > ON??
If yes, contact your carrier. -
IPhoto 11 (9.3) Why won't date range work for 2012?
We upgraded to the new iMac and iPhoto 11 a couple weeks ago.
The Smart Albums look to have converted correctly, including the ones I created for any one years' photos "All - 2011," "All - 2010," and "All - Best of 2009," etc.
Those converted albums contain photos. That is good. That another album does not contain photos is confusing.
I created a new "All - 2012," with the criteria "Data is in the range 1/1/2012 to 12/31/2012," and get no photos.
Scrolling up to "Last 12 months" shows 7,500+, ~ 3,600 of which are 2012.
So I just tried something...
"Date is after 1/1/2011" and got an album of all 2011 photos, stopping at New Years Eve / 12/31... there are no 2012 photos.
Why won't it show 2012 photos?
It's the same camera. A large number of the 2012 photos converted into iPhoto; only a few weeks' worth have been imported into iPhoto straight from the camera since the conversion.
I just don't see a pattern that's causing this.
On a related note... in iPhoto '11, are the icons for all albums, events, Faces, etc. grey? Or should the smart album icon be purple, regular albums blue, etc?
Thanks,
MikeWhy won't it show 2012 photos?
It's the same camera. A large number of the 2012 photos converted into iPhoto; only a few weeks' worth have been imported into iPhoto straight from the camera since the conversion.
On the basis of eliminating the obvious first - check the date reported on any of these shots, and the date on the camera.
in iPhoto '11, are the icons for all albums, events, Faces, etc. grey? Or should the smart album icon be purple, regular albums blue, etc?
This is by design. iPhoto menu -> Provide iPhoto Feedback and let them know what you think.
Regards
TD
Maybe you are looking for
-
How do I add email addresses in a column without them automatically converting to another color with underscores. I want the text to remain text.
-
Why does Lightroom not update all my previews after a batch change?
Hi! I imported more 2,000 pictures. Then I did one batch change (adjusting the curve (tonality) by Lightroom). But it looks like, only on the page, I actually see, the previews are updated. If go to the next page of 24 pictures. At first I see the ol
-
Macbook Air second thoughts. PLEASE RESPOND.
I just recently purchased a MBA '11 64 GB, so far I love it but I'm scared about the storage. I'm a college freshman and I'll be using it mainly for papers and maybe powerpoints and of course web browsing, twitter, facebook, and a little recreational
-
Hello - so far my adjustment brush is having issues engaging. I select the brush, the drop down menu appears, I make my adjustment and nothing registers. I open, close, open, close and open again and sometime it works and sometimes it doesn't. Sugges
-
HT3500 I have Lexmark 6570 printer. How can I hook up to ipad
I have Lexmark 6570 that is wireless. iPad can't find it.