I have an applescript dialog for InDesign CS6 that returns values entered into three text fields. Here's the relevant snippet
set userResponse to show myDialog
if userResponse is true then
set docWidth to edit contents of myWidth as string
set docHeight to edit contents of myHeight as string
set docBleed to edit contents of myBleed as string
destroy myDialog
else
destroy myDialog
error number -128
end if
I want to add the following logic and prevent the user from entering in values larger than 2160. I just want this dialog to display and then return to the previous dialog so they can correct the error:
if 2160 < docWidth or docHeight then
beep 1
display alert "Document cannot be larger than 2160 inches in either dimension." buttons ["Try again"] default button 1
end if
I can't find a way to insert this into the previous dialog without destroying it. Any ideas?
Don't try to solve problems afterwards and define your UI matching your needs. Here you want the user to give integer values, so you need to use integer editboxes:
set myWidth to make integer editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
set myHeight to make integer editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
set myBleed to make integer editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
If the user should be able to insert real values you can use real edit boxes:
set myWidth to make real editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
set myHeight to make real editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
set myBleed to make real editboxes with properties {edit contents:"", min width:60, maximum value:2159, minimum value:1}
Greetings, Michael / Hamburg
Related
Thanks for the help.
I have a textField that I want to update according to the following time increments:
[textField setStringValue:#"Audio 1"]; 7sec.
[textField setStringValue:#""]; 3sec.
[textField setStringValue:#"Audio 2"]; 7sec.
I need the above to loop cumulatively for a total of 5 min.
Any guidance on how to set up NSTimer(s) to accomplish this?
Again - thanks.
Create the timer to fire every second.
Create a counter variable, set it to 600 and decrement it in the timer action. Stop the timer – or whatever you need to do – when the counter reaches zero.
Create two arrays, one with the string values and the other with the durations.
Create a second counter variable for the durations.
Create an index variable and set it to 0.
Get the string value and duration at the given index.
Set the second counter to the duration and assign the string value to the text field.
In the timer action decrement also the second counter. If it's 0 increment the index, if the index is equal to the number of items in the array set the index to 0.
Goto to the step "Get the string value and duration at..."
I created an Applescript that every 600 seconds retrieve the last line of a log file and add it to a Google Sheet spreadsheet.
This is extremely useful, but it is starting to annoy me not knowing when the next action will be performed.
So now I'm trying to display the progress (or countdown in seconds) to the next action in the menubar, so I can, kind of, be aware that the focus application will change.
Can please someone point me in the right direction?
--- Added Information ---
Now, instead of showing a countdown, I want to just simply show how many steps left, and it's still not working. This is a test code I'm working on:
set progress total steps to 12
set progress completed steps to 0
set progress description to "Running..."
set progress additional description to "ETA: 120 Seconds"
repeat with a from 1 to 12
delay 10
set progress completed steps to a
set ETA to a * 10
set progress additional description to "ETA: " & ETA & " seconds"
end repeat
What I'm doing wrong?
Based on the link red_menace gave in comments and the screenshot you provided, here's a script that (I think) will give the results you want. It's not an automator workflow. This is an AppleScript stay-open application. Copy it into Script Editor and save is as an application: choose "Application" from the File Format pulldown menu on the save screen, and make sure you check the Stay open after run handler checkbox. then run the application like normal and see the demo.
use framework "AppKit"
use framework "Foundation"
use scripting additions
property ca : current application
property NSStatusBar : class "NSStatusBar"
property NSMenu : class "NSMenu"
property NSMenuItem : class "NSMenuItem"
property NSImage : class "NSImage"
property NSProgressIndicator : class "NSProgressIndicator"
property NSView : class "NSView"
property NSTextField : class "NSTextField"
property idle_time : 1
global status_bar_item, progress_views, idx
on run
set progress_views to {}
set status_bar_item to NSStatusBar's systemStatusBar's statusItemWithLength:(ca's NSSquareStatusItemLength)
set status_bar_item's |menu| to NSMenu's alloc's initWithTitle:""
set status_bar_item's |menu|'s minimumWidth to 220
my setImage(ca's NSImageNameSmartBadgeTemplate)
my addToStatusMenu(my progress_view_obj("Number 1"))
my addToStatusMenu(my progress_view_obj("Number 2"))
set idx to 0
end run
on idle
set idx to idx + 1
repeat with this_obj in progress_views
set rand_numb to (random number from 1 to 9)
(this_obj's progress_indicator's incrementBy:rand_numb)
this_obj's changeLabel("Adding: " & rand_numb)
end repeat
if idx > 20 then
quit
end if
return idle_time
end idle
on quit
-- remove status item and quit
NSStatusBar's systemStatusBar's removeStatusItem:status_bar_item
continue quit
end quit
on addToStatusMenu(obj)
set statusMenu to status_bar_item's |menu|
statusMenu's addItem:(obj's menu_item)
set end of progress_views to obj
end addToStatusMenu
on progress_view_obj(label_value)
script prog_view_obj
-- text field
property progress_indicator : missing value
property menu_item : missing value
property label_field : missing value
global content_view
-- make label field
set label_field to NSTextField's labelWithString:label_value
set label_field's translatesAutoresizingMaskIntoConstraints to false
-- progress indicator
set progress_indicator to NSProgressIndicator's alloc's initWithFrame:(ca's NSMakeRect(0, 0, 200, 20))
set progress_indicator's indeterminate to false
progress_indicator's setStyle:(ca's NSProgressIndicatorStyleBar)
progress_indicator's startAnimation:me
set progress_indicator's translatesAutoresizingMaskIntoConstraints to false
-- content view for menu item
set content_view to NSView's alloc's initWithFrame:(ca's NSMakeRect(0, 0, 200, 100))
set content_view's translatesAutoresizingMaskIntoConstraints to false
content_view's addSubview:label_field
content_view's addSubview:progress_indicator
-- constraints to arrange elements
--set view_height_constraint to content_view's heightAnchor's constraintEqualToConstant:100
--view_height_constraint's setActive:true
set lf_left_margin to content_view's leadingAnchor's constraintEqualToAnchor:(label_field's leadingAnchor) |constant|:-10
lf_left_margin's setActive:true
set pi_left_margin to content_view's leadingAnchor's constraintEqualToAnchor:(progress_indicator's leadingAnchor) |constant|:-10
pi_left_margin's setActive:true
set pi_right_margin to content_view's trailingAnchor's constraintEqualToAnchor:(progress_indicator's trailingAnchor) |constant|:10
pi_left_margin's setActive:true
set top_spacing_const to content_view's topAnchor's constraintEqualToAnchor:(label_field's topAnchor) |constant|:-10
set mid_spacing_const to label_field's bottomAnchor's constraintEqualToAnchor:(progress_indicator's topAnchor) |constant|:-10
set bott_spacing_const to content_view's bottomAnchor's constraintGreaterThanOrEqualToAnchor:(progress_indicator's bottomAnchor) |constant|:10
top_spacing_const's setActive:true
mid_spacing_const's setActive:true
bott_spacing_const's setActive:true
content_view's updateConstraints()
-- create and flesh out menu item
set menu_item to NSMenuItem's alloc's init()
set menu_item's view to content_view
content_view's updateConstraints()
on changeLabel(label_value)
set label_field's stringValue to label_value
end changeLabel
on changeMinValue(val)
set progress_indicator's minValue to val
end changeMinValue
on changeMaxValue(val)
set progress_indicator's maxValue to val
end changeMaxValue
on changeValue(val)
set progress_indicator's doubleValue to val
end changeValue
on currentValue()
return progress_indicator's doubleValue() as integer
end currentValue
end script
run prog_view_obj
return prog_view_obj
end progress_view_obj
on setImage(imageName)
status_bar_item's button's setImageScaling:(ca's NSImageScaleProportionallyDown)
status_bar_item's button's setImage:(NSImage's imageNamed:imageName)
status_bar_item's button's setImagePosition:(ca's NSImageLeft)
end setImage
You shouldn't need to change anything except in the run and idle handlers — the first to set up the menus and the second to increment the progress bars or update the labels as needed. You can change how frequently the indicators update by increasing or decreasing the idle-time property (it's currently set to run the idle loop once a second). You'll only need to get into the big, messy handler if you need to change the layout or size of the menu items.
Technical point: I've put each progress view inside a script object (script prog_view_obj) to make it easier to work with. That may take some time for you to wrap your head around — it's tricky AppleScript — but at any rate, there's a bunch of convenience handlers at the end of the script object definition that you may find useful.
This is making me lose my mind. Here's a short version of thee code that I'm trying to get to work. It's returning bizarre values and giving me errors at random height and width settings. I can't for the life of me figure out where I went wrong! I thought my logic gate to determine the inputs was rock solid! Any help would be greatly appreciated!
tell application "Adobe InDesign CS6"
activate
set myDoc to active document
set origLevel to user interaction level of script preferences
set user interaction level of script preferences to interact with all
set myDialog to make dialog with properties {name:"Make Template", can cancel:true}
tell myDialog
tell (make dialog column)
tell (make border panel)
tell (make dialog column)
make static text with properties {static label:"Width:", min width:60}
make static text with properties {static label:"Height:", min width:60}
make static text with properties {static label:"Bleed:", min width:60}
end tell
tell (make dialog column)
set myWidth to make text editboxes with properties {edit contents:"", min width:60}
set myHeight to make text editboxes with properties {edit contents:"", min width:60}
set myBleed to make text editboxes with properties {edit contents:"", min width:60}
end tell
tell (make dialog column)
make static text with properties {static label:"in", min width:0}
make static text with properties {static label:"in", min width:0}
make static text with properties {static label:"in", min width:0}
end tell
tell (make dialog column)
make static text with properties {static label:"", min width:25}
end tell
end tell
end tell
end tell
set userResponse to show myDialog
if userResponse is true then
set docWidth to edit contents of myWidth as string
set docHeight to edit contents of myHeight as string
set docBleed to edit contents of myBleed as string
destroy myDialog
else
destroy myDialog
error number -128
end if
tell myDoc
if docHeight > docWidth then
set bigDim to docHeight
else
set bigDim to docWidth
end if
if bigDim ≤ 216 then
set buildSize to "1"
else if bigDim > 216 and bigDim ≤ 432 then
set buildSize to "2"
else if bigDim > 432 and bigDim ≤ 864 then
set buildSize to "4"
else if bigDim > 864 and bigDim ≤ 2160 then
set buildSize to "10"
end if
set newWidth to (docWidth / buildSize)
set newHeight to (docHeight / buildSize)
set newBleed to (docBleed / buildSize)
set document bleed top offset of document preferences to newBleed
set page width of document preferences to newWidth
set page height of document preferences to newHeight
end tell
set user interaction level of script preferences to origLevel
end tell
You write
set docWidth to edit contents of myWidth as string
set docHeight to edit contents of myHeight as string
and in fact you compare a string with an integer: if bigDim ≤ 216 then. To handle your code Applescript has to convert one of these values and it looks like it converts the value 216 to a string "216". Using string comparison the string "5" is greater than "216" and fits the comparison else if bigDim > 432 and bigDim ≤ 864 then, because the string "5" fits between "432" and "864".
What about converting the edit contents to integer?
set docWidth to edit contents of myWidth as integer
set docHeight to edit contents of myHeight as integer
BTW the used code set newWidth to (docWidth / buildSize) later in your script worked only because Applescript is clever enough to convert both values to numbers because it just don't make sense to divide two strings ;-)
Enjoy, Michael / Hamburg
How can I restrict the postback after exceeds maximum value in Telerik RadNumeric Textbox...
Here is my code..
<telerik:RadNumericTextBox ID="tbDays" AutoPostBack="true" MaxValue="50"
runat="server" ontextchanged="tbDays_TextChanged">
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
On ServerSide:
protected void tbDays_TextChanged(object sender, EventArgs e)
{
int itemCount = int.Parse(tbDays.Text);
///Doing Some stuff..
}
EDIT: How to restrict the postback when we click upper arrow in the numeric textbox after reaching the maxvalue?? or Is it possible to disable the upper arrow after reaching maxvalue.??
"Use the MaxValue and MinValue properties to specify a range for the numeric text box. If the user tries to enter a value that is greater than the value of the MaxValue property, the numeric text box automatically changes the value to MaxValue. Similarly, if the user tries to enter a value that is less than the value of the MinValue property, the numeric text box automatically changes the value to MinValue." - from Telerik
There shouldn't be a value that exceeds the max value as the box should change anything that exceeds the max value to the max value.
I have simple cell and formula cell in both of case i want to set cell type number but it takes default general type. Plz help me how can i set cell type general to number type.
We can change cell format in following way:
Dim CellFormat As HSSFCellStyle = HSSFWorkbook.CreateCellStyle()
CellFormat.DataFormat = &H29
Here &H29 is direct value of specific format if we want to get format then can follow:
Dim CellFormat As HSSFCellStyle = HSSFWorkbook.CreateCellStyle()
CellFormat.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0")