Autohotkey: how to determine clipboard buffer contents size - size

I have a script that scrapes a certain portion of the screen and acquires about 100-200 bytes long text in to the clipboard. Sometimes, due to web server timeout or missing CSS definitions etc, the page doesn't render correctly and the sane mouse drag, selects a much larger amount of text and copies it to the clipboard.
I want to be able to notice this situation and scrap the clipboard contents and run my script again, till it is at the expected size of 100-200 bytes. Finally abort the script if large buffer keeps happening for certain number of times.
I have the logic for it but only thing I am not able to figure out the clipboard size and how to get it inside AHK script. Is there a predefined variable for it ? Or is there another, more complicated method ? What comes to mind is to paste the contents into notepad and save it. Then look at the file size, but it is very convoluted. I want something without a disk write operation.
Any ideas ? I saw the strlen command but not sure how to use it...

If it is text in your clipboard this works:
ClipSize := strlen(clipboard)
Example Script
sClip:=GetClipboardSize(Clipboard)
sClip_a:=GetClipboardSize(ClipboardAll)
MsgBox Clipboard Size: %sClip%`nClipboardAll Size: %sClip_a%
GetClipboardSize(c) {
if (!s:=strlen(c)) {
tmp:=A_temp "\clipboardsize_" A_TickCount "~~tempfile~~.tmp"
FileDelete,%tmp%
FileAppend,%ClipboardAll%,%tmp%
FileGetSize,s,%tmp%
FileDelete,%tmp%
}
return s
}

Related

How to make long text fit into a text_frame? Python-pptx

I'm working with python-ppt to create a portfolio of candidates in a Powerpoint presentation. There is one candidate per slide and each of them has provided information about themselves like name, contacts and a minibio (the problem I'm here to solve)
The text_frame, created with values of height and width, must fit the slide but must a contain all lenght of minibios, which is not happening.
In a long phase (>200 char, with font size 12) it exceeds the size of the text box and get "out" of the slide, so, in presentation mode or a PDF file, the "overrun" of text is lost
Is there any way to confine the text to the shape/size of the text_frame? (extra help if the solution wont change font size)
Just found one parameter that helped to find the answer
When creating a text_box object with slides.shapes.add_textbox() and adding a text_frame to it, the text_frame.word_wrap = True limits the text to be contained inside the dimentions of the text_box
The code shows it better
# creates text box with add_textbox(left, top, width, height)
txBox = slide.shapes.add_textbox(Cm(16),Cm(5),Cm(17),Cm(13))
tf = txBox.text_frame
tf.word_wrap = True
Before word_wrap parameter
After word_wrap parameter
The short answer is "No". PowerPoint is a page-layout environment, and much like the front page of a newspaper, text "story" content needs to be trimmed to fit the allotted space.
We're perhaps not used to this because word-processing, spreadsheet, and web-page content is "flowed" into a (practically) unlimited space, but the area of a PowerPoint slide is quite finite. Also, using it for large text blocks is somewhat of an off-label use. There is a certain amount of flexibility provided by reducing the font size, but not as much as one might expect. Even accommodating 20% additional text requires what appears as a pretty radical change in font size.
I've encountered this problem again and again, and the only solution I have ever seen work reliably is hand-curating the content to fit.
python-pptx has one experimental feature to address this but its operation has never been very satisfactory and it's tricky to get working. https://python-pptx.readthedocs.io/en/latest/api/text.html#pptx.text.text.TextFrame.fit_text
The business of fitting text is the role of a rendering engine, which python-pptx is not.

Update of multiple "link-fields" through VBA in word very slow

I have a word file with approximately 750 fields which link to an Excel file (all to single cells, mostly not the same cell, always the same file), e.g.:
{ LINK Excel.SheetMacroEnabled.12 C:\\Dir1\\Dir1\\ExcelFile.xlsm Daten!Z1S1 \t \* MERGEFORMAT }
Updating the fields (CRTL+A -> F9) right after restarting Word is fairly quick. But if Word wasn't restarted it sometimes takes 10-20 minutes. On some PCs even restarting doesn't help.
When I checked the Task-Manger I saw multiple Excel-Instances could it be the Word open and closes the file for each field, even they all are linked to the same file. Is there a way to force Word to keep the file open?
I played around with the following VBA code with different variations, but so far I had no luck. This is the code I'm trying to get to work (going through all stories) and updating the fields:
Application.ScreenUpdating = False
ThisDocument.StoryRanges(i).Fields.Update
Selection.Fields.Update
I also tried to go through each field individually (which is undesirable since it means I have to build my own progress bar), but it doesn't resolve the performance issue:
Application.ScreenUpdating = False
ThisDocument.StoryRanges(i).Fields(j).Update
Selection.Fields.Update
DoEvents
Is there a way to prevent the low performance, or at least a way to further troubleshoot the problem?
Please Note: I also posted two other questions within this context:
VBA (Word): force user form to update in real time
How to show the progress of the “Fields.Update”-Method in VBA (Word)

Excel VBA: Memory Exceeds Limits on Second Import

I am using 32-bit 2013 Excel with VBA extensively. I have disabled hardware graphics acceleration and COM add-ins, yet I still struggle with the following problem:
I am importing the contents of another large workbook with formatting on the cells but with no formulas (~3mb Excel file) into the problematic Excel workbook. On the first attempt - when the contents have not been imported yet - the import succeeds. I am importing the content via VBA similar to the following code:
Application.Workbooks(F_Home).Activate
Workbooks(F_Home).Sheets(Sheet1).Visible = xlSheetVisible
...
Application.Workbooks(F_Source).Activate
Workbooks(F_Source).Sheets(S_Source).Cells.Copy Destination:=Workbooks(F_Home).Sheets(Sheet1).Cells
Application.Workbooks(F_Home).Activate
F_Home is the problematic Excel workbook and F_Source is the workbook with the content we are importing in. When doing this the first time it works, and then I save the file and close out of it, and reopen the file, and try this a second time. On the second time we attempt to import the contents (when the contents already imported) the F_Home workbook crashes with the Out of Memory Error (There isn't enough memory to complete this action...) on the line that copies F_Source contents to F_Home.
Using Process Explorer I've found that the Excel process usually runs around 600mb - 700mb in virtual memory size, but when we run the VBA script to import the contents a second time, the virtual memory size suddenly jumps to 4gb (this does not happen on the first time around, which stays at the 600mb - 700mb range). How should I fix this? I cannot do a workaround such as saving the file before importing the contents a second time, because the timestamp on the file is used and saving the file through VBA will confuse some users.
Thank you for your help.
Copy and pasting the whole sheet is not a wise approach. Let's assume you have data from "A1:Z99999". You can do this which is going to be much faster.
Set S_Range = Workbooks(F_Source).Sheets(S_Source).Range("A1:Z99999")
Set H_Range = Workbooks(F_Home).Sheets(Sheet1).Range("A1:Z99999")
H_Range.Value = S_Range.Value
Also read why you should avoid selecting and activating in vba.

change length of multiple mp3 files

I have several hundred short mp3 files (1-5 seconds) I would like to trim them. namely, the length should be rounded up getting a whole second. for example if a mp3 file is 1.32s long, it should be afterwards 2.00 in length, the lack of time should be filled with silence. is it possible to automate this process? if so with what tool? thanks
Try Audacity, it allows batch processing: http://manual.audacityteam.org/index.php?title=Batch_Processing
I'm not sure whether it will do everything that you need it to do but it's worth checking out what all your options are within this program.
[EDIT]
Ok, so if you do have hundred and also might be something useful for you in the future this is what I would recommend or would personally do myself.
Get mp3DirectCut [freeware]
Get AutoHotKeys [freeware]
Learn how to use both, particularly AutoHotkeys
Save All filenames into a spreadsheet
Create a script that does the following with mp3DirectCut
Load file by name on spreadsheet
Hit the "End" button
Paste a pre-copied silent 1 sec long clip from clipboard
Parse the NAV field in the program (bottom left) to get the Total length
Calculate and enter desired endpoint to total length for Selection (then hit Enter)
Hit the "Del" button
Save complete song
Repeat

Printing only starts after last page spools

I'm having a problem that printing in VB.net where any network printer I choose is waiting until the last page is spooled before printing begins. However I'm looking to have it begin printing after the first page.
The printer is set to 'Start printing immediately', and this is giving me huge problems as we're trying to print duplex documents that may be 75 ~ 100 pages long.
Any ideas?
Can you paste a little sample of the code you are using to print? First off, I would look at the queue itself and ensure that things like the Print Processor are set to RAW and also confirm that other applications such as Word have no issue 'starting immediately' to this device.
Why is this such a big deal? Does you application take a long time to generate the data that this causes issue? You should be able to generate the print output quickly (assuming it's not a bunch of high res images or something) and get it into the queue fast. Assuming you have an up to date printer that's doing 30-40ppm the entire process should only take a couple of minutes.