Here's my code:
set todayDate to do shell script "date '+%Y/%m/%d'"
set salesRef to "COMPANY-AB" & "-" & theCustomerInitials & "-" & todayDate & "-" & theCustomerID
set the clipboard to salesRef as text
display dialog salesRef as text buttons {"OK"} default button 1
Here's the UI: http://i.imgur.com/sfRnpr6.png
I'd like to make the text 'Copied!' appear when the successfully completes the clipboard line, but remain hidden until then, and also populate the text field at the bottom with the 'salesRef' variable, so the user get's an output.
Essentially then, I'll be able to remove the display dialog. But I can't work out how to do this :(
Successfully managed this by adding these lines:
property theTextField : missing value
…
theTextField's setStringValue:salesRef
Then created a connection to the text field in IB by control dragging from the App Delegate to the text field, and selecting the property.
Are you ok with NSAppleScript?
if so here is an example:
NSAppleScript *myScriptThatShouldGimmeStuff = [[NSAppleScript alloc] initWithSource:
#"return (text returned of (display dialog \"gimme your input:\" default answer \"\" buttons {\"Ok\"} default button 1))"];
//this previous line is the applescript
NSAppleEventDescriptor *theStuff = [myScriptThatShouldGimmeStuff executeAndReturnError:nil];
self.myTextBoxToPutInputIn.stringValue = [theStuff stringValue]; //[theStuff stringValue] is the result returned
/|\
/ | \
/ | \
|
|
//don't forget to change this
//(I didn't comment out the arrow because i want xcode
// to throw you an error so you don't forget to change that).
So it is not clear from you code what you are doing, but IF you are using ASOC, then you have to define OUTLETS to the controls in your UI, and then you just set the .stringValue of the outlet to whatever string you want to appear in them.
If you don't know how to set up outlets, watch this video and download the example code (look for INTRO VIDEO on the page):
http://www.macosxautomation.com/applescript/develop/index.html
Or for another step-by-step example, here:
http://asobjcresources.weebly.com/getting-a-text-field-input.html
Related
In my macOS app I’m trying to update an AppDelegate property by editing a Table View Cell.
I created a sample project (Table View example project with array controller) using tips from the answer to this post.
I’m using macOS Big Sur (11.6.8) and Xcode 12.5.1. I'll be glad to supply a source archive download link or email it if requested. When I tried to add a link in this post it was rejected.
Here's my AppDelegate script:
script AppDelegate
property parent : class "NSObject"
property msg : ""
-- IBOutlets
property theWindow : missing value
property tableViewData : missing value
property arrayController : missing value
property showTableViewData : missing value
on `applicationWillFinishLaunching_(aNotification)`
appInit()
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
on appInit()
set my msg to (current date & return & return & "Initializing…") as string
delay .5
initTableView()
set my msg to (current date & return & return & "Ready.") as string
delay .5
end appInit
on initTableView()
set my tableViewData to {}
set my tableViewData to {{adName:("C21 ad" as string), pageNumber:("001" as string)}, {adName:("ERA ad" as string), pageNumber:("002" as string)}}
end initTableView
on `showTableViewData_(sender)`
set my msg to (current date & return & return & "showing tableViewData....") as string
delay .5
set displayText to ""
repeat with thisRecord in tableViewData
display alert "adName: " & (adName of thisRecord as string) & return & "pageNumber: " & (pageNumber of thisRecord as string)
end repeat
set my msg to (current date & return & return & "Ready.") as string
delay .5
end `showTableViewData_`
end script
How it works
As you can see I have hardcoded two records which I use to populate the tableViewData property on initialization which in turn is displayed in the table view. For some reason the adName data is not being displayed, but that bug is not what this post is about.
App initialized
Clicking the button reads the tableViewData property, iterates the records displaying them via an alert (so we can see it's contents).
Record display
Aside from the adName not displaying, so far so good.
Next, I edit the pageNumber table view cell for the first record (changing it from "001" to "777" and hitting return). When I click the button the first record is displayed which still shows a pageNumber value of "001" (instead of the "777" value I entered).
Record display after editing
Here are some shots of the table view cell attributes, connections, and bindings:
Attributes
Connections
Bindings
I tried selecting the bindings setting "Continuously Updates Value" but that doesn't seem to help; my tableViewData property is not updated with the newly entered data in the table view cell.
Most of the current developer docs use Obj-C or Swift instead of AppleScript and iOS or tvOS related. I'm using Xcode 12.5.1 because of problems binding UI elements to my code.
Thanks for taking the time to look this over.
The contents of tableViewData doesn't change but content of arrayController does. Try
repeat with thisRecord in content of arrayController
display alert "adName: " & (adName of thisRecord as string) & return & "pageNumber: " & (pageNumber of thisRecord as string)
end repeat
To make it work, use a Script Object instead of a record.
on makeAd(nameOfAd, pageNr)
script ad
property adName: nameOfAd
property pageNumber: pageNr
end script
return ad
end makeAd
on initTableView()
set my tableViewData to {makeAd("C21 ad", "001"), makeAd("ERA ad", "002")}
end initTableView
One of our VB6 project form is having a combo box. It's style is set to 2(Drop-down List Box).
When style is set to 2, its Text property becomes read-only. We cannot assign value to it.
But in our project some one has written code to assign string to Text property, and is working fine.
combobox1.Text = "Something" 'working
If i create a same kind of combo box with same properties, i am not able to assign string to text property.
I am getting error runtime error 383 'text' property is read-only
combobox2.Text = "Something" 'Not working
Can anyone help me understanding what i am missing.
The reason why someone else code worked is because they had the dropdown combo property selected and not the dropdown list. You need to add items to the combo list and then set the listindex to 0 as per below -
Combo1.AddItem "MyComboCaptionHere"
Combo1.AddItem "Hi"
Combo1.AddItem "There"
Combo1.ListIndex = 0
This will show a "caption" of MyComboCaptionHere.
script AppDelegate
property theWindow : missing value
property displayLabel : missing value
on applicationWillFinishLaunching:aNotification
display dialog "Are you ready?" buttons {"Yes", "No"} default button "Yes"
end applicationWillFinishLaunching:
if result = {button returned:"No"} then
display alert "That's a shame."
tell application "This Application"
quit
end tell
else if result = {button returned:"Yes"} then
set testVariable to "this is a test"
end if
end script
So, this is an example of an app I'm working on in AppleScriptObjC. I've taken a lot out and replaced things with different strings, but this is the basic layout.
How can I get the value of 'testVariable' into the 'displayLabel' property, which is linked to a label in the interface builder? The label is empty initially, but I want the value of 'testVariable' to populate it once the script has been run.
Thanks!!!
The syntax is pretty similar to the ObjC syntax
ObjC
displayLabel.stringValue = testVariable;
AppleScriptObjC
set displayLabel's stringValue to testVariable
I'm trying to insert an image path into an Access database. I have a hyperlink field named logo, and I'm using this code to browse for images:
Dim dialog As FileDialog
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Title = "Select A File To Use As A Logo"
.Filters.Clear
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg;*.bmp;*.png"
.ButtonName = "Use This File"
If .Show = True Then
Me.im1 = .SelectedItems.Item(1)
End If
End With
im1 is an unbound textbox used to view the path. The problem is that it's displaying the file path as text, not as a hyperlink. I'd like to display the file name as a hyperlink in my form in im1. Is this possible?
Text is text. If you want something to show up as a hyperlink you need to tell your textbox that's what it's doing. It can't guess.
im1.IsHyperlink=True
However, The easier thing to do is probably to use a Label instead of a textbox. Set the .HyperlinkAddress property to your link address
I am trying to make a small calculator app.
When a UIButton is pressed, the Button title is added to a UITextField.
kind of:
myuitextfield.text = [myuitextfield.text stringByAppendingString:[button currentTitle];
When I reach the end of my textfield, the text gets truncated. How can I disable this, so the textfield starts scrolling automatically and allows adding more characters?
I tried every possible option in Interface Builder, without any luck.
Isn't the UITextField supposed to scroll automatically? I can see this behavior when a native keyboard is used and text is entered.
I have chosen UITextField, as I need only 1 Line.
To illustrate the Problem:
When I enter text using my custom UIButtons text gets truncated
When I tap the UITextField and enter text using the keyboard I can enter unlimited text and the text is not truncated.
If you are facing this issue on iOS7, I've managed to fix it after been inspired by this post. In my case I had a field for entering an email address and after reaching the edge, the user could carry on typing but the text would be invisible (off-field).
First, add a callback to your UITextField so that you can track a text change to the field:
[self.field addTarget:self action:#selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
Then evaluate the size in pixels of the entered string as it is typed and change the text alignment from left to right when reaching the edge of the field area:
- (void)textFieldDidChange:(NSNotification *)aNotif{
float maxNumPixelsOnScreen = 235; // Change this value to fit your case
CGSize maximumSize = CGSizeMake(maxNumPixelsOnScreen + 10, 1);
NSString *aString = self.field.text;
CGSize stringSize = [aString sizeWithFont:fieldFont
constrainedToSize:maximumSize
lineBreakMode:NSLineBreakByWordWrapping];
self.field.textAlignment = NSTextAlignmentLeft;
if (stringSize.width >= maxNumPixelsOnScreen)
self.field.textAlignment = NSTextAlignmentRight;
}
Note:
self.field is the offending UITextField
maximumSize: I'm adding 10 the the width to be slightly over the limit defined
fieldFont is the UIFont used to render the text field
Hope it helps!
you have to add UITextview and limit the number of lines to 2.Textfield doesnt work with two lines.Textview is same as textfields except the delegates and some properties differ.