make an application ask for password applescript - passwords

I'm trying to write an AppleScript Code which makes Firefox ask me for a password when I open it. This is what I got, but somehow it doesn't work:
on activate
display dialog "Please enter your password" buttons {"Cancel", "Okay"} default answer "" default button 2
set x to text returned
if x is "Password" then
tell application "Firefox"
activate
reopen
end tell
else
say "please try again"
end if
end activate
I also need to know where to save the Script, when it is correct. Thanks a lot!

There was an error in the set x to text returned. It needs to know what dialog you're referring to. See below.
on activate
set passwordRequest to display dialog "Please enter your password" buttons {"Cancel", "Okay"} default answer "" default button 2
set x to text returned of passwordRequest
if x is "Password" then
tell application "Firefox"
activate
reopen
end tell
else
say "please try again"
end if
end activate

Heres how paste this in ur script editor then save as whatever the name you want but also save as a application when you do that u can change the app log to what ever you want then run the
on run
set defaultanswer to display dialog "Please enter a passphrase to use this script." default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue" with hidden answer
set x to text returned of defaultanswer
if x is "ANY PASSWORD U WANT" then
tell application "ANY APPLICATION U WANT"
activate
reopen
end tell
else
say "please try again"
end if
end run

Related

How to reference the users current textbox?

In access I am trying to not let the user exit a textbox unless they have filled it out (i.e. not left it null). This is to be done in a function in order to cut down on code. In VBA is there some way to stop the user from exiting the function? (I know about setting the focus but I need the code to work from a multitude of different textboxes)
For reference my current code is as follows;
Function Reload()
If IsNull(EmployeeID.Value) Or IsNull([First Name].Value) Or IsNull([Surname].Value) Or IsNull(DOB.Value) Or IsNull(Position.Value) Or IsNull(Position.Value) Or IsNull(Mobile.Value) Or IsNull(Email.Value) Or IsNull(Address.Value) Or IsNull(Suburb.Value) Or IsNull(Postcode.Value) Or IsNull([Start Date].Value) Or IsNull(UserLogin.Value) Or IsNull(UserPassword.Value) Then
MsgBox "Please fill out all fields"
Else
DoCmd.RunCommand acCmdSaveRecord
Form.Refresh
End If
End Function
Thanks
The best technique I know is to use the BeforeUpdate event to run data validation. Using your if statements if the data is not valid then set
Cancel = True
and the data will not write. You would probably prefer to disable the default record navigation and form close buttons and use custom buttons so that you can trap the invalid data error and prevent moving to a new record or closing the form. But even if you allow the user to use the built in navigation buttons or close button Access will throw up error messages about being unable to save the current record and prompt the user if he wants to proceed.
You can also go a step further and captue which fields are invalid and present a message box.
Msgbox ("The following fields were left blank and must be entered to save this record:" & vbCrLf & "Field 1" & vbCrLf & "Field 2")
A little modification of the text input limiter i use in our chat room should help. New function I have called it MustINPUT and call it on the LostFocus of the text boxes that you don't want to move from with out input.
Private Sub MyTextBox_LostFocus()
Call MustINPUT (Me.MyTextBox, 0)
End Sub
Just change the message for your users.
Sub MustINPUT(ctl As Control, iMaxLen As Integer)
'Call MustINPUT(Me.txtSayThis, 0)
If Len(ctl.Text) = iMaxLen Then
MsgBox "Please Type something", vbExclamation, "Input Needed"
ctl.Text = Left(ctl.Text, iMaxLen)
ctl.SelStart = iMaxLen
End If
End Sub
Hope this help. DR ,

Making a form that users enter a value into text boxes a certain number of times

I have a series of text boxes that are hidden, except one which users enter a value into. After a button is pressed, this text box disappears and the rest appear. From there, I want users to be able to enter different values into each text box. These values will be saved as variables. From there, users press a button and enter new values into the text boxes, until values have been entered into the text boxes for each number up to the first value entered into the hidden text box.
I'm not sure how else to explain this, but please let me know if you have any questions.
Correct me if im wrong. i think you want an input in different textbox?
Like textbox1 = 1, textbox2 = 2 and so on. If this is right then try this.
Lets try this to your 3 textbox for an example.
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
If TextBox1.Visible = True Then
If Trim(TextBox1.Text) <> "" Then
TextBox1.Visible = False
TextBox2.visible = True
Else
MsgBox("Required")
'or user error provider.
End If
Exit Sub
End If
If textbox2.visible = True Then
If Trim(TextBox2.Text) <> "" Then
TextBox2.Visible = False
TextBox3.visible = True
Else
MsgBox("Required")
'or user error provider.
End If
Exit Sub
End If
'and so on
End Sub
hope this is what you want. just basic but maybe usefull :)
This is the workflow of what you want to accomplish in JavaScript. VB.Net has similar functions to Visibility. https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
In the visual editor you can create buttons and add Click events to them, this is basic so I won't tell you how to do it. Google if you can't.
var options = document.getElementsByClassName("options");
var optionsSetOne = document.getByClassName('optionsSetOne');
This will select all your options. Now that you have all your options selected and in a variable called options you can play around with the visibility, as the user progresses thought the buttons.
First I would set all my options to hidden with:
options.style.visibility = 'hidden';
After the users progresses and clicks the button, I will make the first set of the options visible. With:
$('#buttonOne').click(function(){
optionsSetOne.style.visibility = 'visible';
});
This is the basic workflow of what you want to accomplish, you have to figure out how to save all the information the user gives to you.

Disabling menu items using other winform (vb.net)

Hi I have a problem with my code: I have two windows form Menu and Login. I set Menu as MdiParent.
So this is what it looks like.
My problem is when I log in as Clerk I want User Account to be disbled. My code in Login Form is this:
If myReader.Read Then
MsgBox("Log-in Successfully", vbInformation, "Log-in")
If cmbtype.Text = "Clerk" Then
Menu.useracc.Enabled = False 'but i got an error here
Else
Menu.useracc.Enabled = True 'same as here
End If
Me.Close()
clear()
Else
MsgBox("Username and Password do not match. Please check and log-in again.", vbCritical, "Log-in Failed")
End If
What would be the right code to disable menu item from my Menu Form when Login Form closes.

Assistance with a popup box?

So, I literally have one more thing to do to finish my Calculator, which is make an error box popup if the textbox is empty. Currently, it shows a message, saying an error has occurred. I want it to simply launch a popup if the textbox is empty, and a "Continue" button to close the window.
If you want a simple popup, try this:
if textboxNum1.Text = "" OR textboxNum2.Text = "" Then
MsgBox("Textboxes are empty!")
else
'Enter process here
End if
Or try this:
if(textboxNum1.Text = "" OR textboxNum2.Text = "") Then
MsgBox("Textboxes are empty!")
else
'Enter process here
End if

Raising UAC window loads my form twice

I am using following code to raise UAC window. It works fine but my form that contains button to raise this window is shown twice. I mean if I put it in CopyFiile Button, when I click this button, it raises UAC windows, copies file, gives success message and then opens another instance of the same form that contains copyfile button. Please help.
Dim proc As New ProcessStartInfo
proc.UseShellExecute = True
proc.WorkingDirectory = Environment.CurrentDirectory
proc.FileName = Application.ExecutablePath
proc.Verb = "runas"
Try
Process.Start(proc)
Catch
' The user refused to allow privileges elevation.
MsgBox("Permission denied by user ! Can not proceed.", MsgBoxStyle.Critical)
vrIfDenied = 1
Return
End Try
Correct me if I'm wrong but i see your proc filename property is equals to it's self. You are running the same application and makes 2 instances of the current application
Add this to your code:
<DllImport("shell32.dll", EntryPoint:="IsUserAnAdmin")> _
Public Shared Function IsUserAnAdmin() As Boolean
End Function
Now when your app loads, check to see if it is running as elevated priviledges, and grey out the Copyfile button like this if it isn't:
If IsUserAnAdmin() = False Then
btnCopyFile.enabled=false
ElseIf IsUserAnAdmin() = True Then
btnCopyFile.enable=true
btnElevateMe.enabled=false
End If
Now you can add a 2nd button (btnElevateMe) which will use the code you originally posted to elevate the priviledges and bring up the UAC prompt. When running WITH priviledges, it will be greyed out.
Also, add to your code after "End Try" this:
Application.Exit()
And it will close the app after starting a second instance with elevated priviledges.