Тёмный

AppleScript Tutorial : Conditionals 

ClickingKeys
Подписаться 1,2 тыс.
Просмотров 2 тыс.
50% 1

Thanks for checking out my AppleScript tutorials series designed for beginners (absolute noobs). In this video I’ll use Script Editor (Apple’s free compiler) to cover conditional statements. These are IF, THEN, ELSE statements in AppleScript that let you control what segments of code are processed based on the conditions evaluating to true or false.
For more AppleScript tutorial videos, check out this play list.
• Learn to AppleScript (...
If you're interested in watching full scripts being written, have a look at this play list.
• AppleScript Project Ex...

Хобби

Опубликовано:

 

20 янв 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 10   
@dragispagata7825
@dragispagata7825 10 месяцев назад
thank you this is awesome
@galaxy_glitch9453
@galaxy_glitch9453 Год назад
Hello I have a question. How do you make different buttons lead to different part? Like if you choose "ok" you get a thank you but if you choose "more" you get more information? Is there a way to do that?
@ClickingKeys
@ClickingKeys Год назад
Hey galaxy_glitch, thanks for the question. Yes, you can do what you’re asking about. When you display a dialog with custom buttons, you can set your variable to “button returned of” to see what button the user selected. Example: set btn to button returned of (display dialog “Please select a button”) In that example, btn will be either “OK” or the value of any buttons you add to your dialog.
@raye9348
@raye9348 Год назад
This is a great explanation! One question on this topic, I have seen a few examples of if statements done with numerical examples. Is there a way to do it with words or if a phrase is found? Like, I want to run an if statement for when a word or a phrase is matched then it will run a script for that phrase. And if a different word or phrase is found it will run a different script. Is it possible to run something like this? Thanks!
@ClickingKeys
@ClickingKeys Год назад
Yes, you would just do something like this… if thevar = “word” then - do something cool else if thevar = “something else” then - do something different end if
@vegard3055
@vegard3055 2 года назад
Hi 😊 I have just started to learn how to use applescript and I realy like your tutorials! How would you write a script to toggle on/off standard use og function keys in system preferenses? I’m using a software where the function keys are used often, and it would be nice to have a script that was activated by a shortcut.
@ClickingKeys
@ClickingKeys 2 года назад
Hey Vegard, thanks for the message I greatly appreciate it. I've added AppleScript code below that does what you've requested. I've intentionally added a lot of "extras" in it since you're trying to learn AppleScript. I thought it was a good way for you to see a few different things happening in a code example. Let me know how you get on with it! ########## START APPLESCRIPT CODE ########## on run set theOption to button returned of (display dialog "Turn the function keys..." buttons {"Off", "On"} default button "On") # ASK WHICH OPTION THE USER WANTS tell application "System Preferences" activate # OPEN SYSTEM PREFERENCES set the current pane to pane "Keyboard" # OPEN THE KEYBOARD PREF PANE tell application "System Events" tell process "System Preferences" tell tab group 1 of window "Keyboard" set statusValidated to false repeat with i from 1 to 100 # REPEAT TO ENSURE WE ALLOW FOR SLOW LOADING PREFERENCE PANES ON SOME COMPUTERS try set theCheckbox to checkbox "Use F1, F2, etc. keys as standard function keys on external keyboards" set theProperties to properties of theCheckbox set theValue to value of theProperties # GET THE CURRENT STATUS OF THE CHECKBOX if theValue = 1 and theOption = "Off" then click theCheckbox # TOGGLE THE STATUS OF THE CHECK BOX, IT'S NOT SET THE WAY WE WANT set statusValidated to true # WE KNOW THE STATUS IS SET THE WAY WE WANT exit repeat # WE'VE DONE WHAT WE WANTED, EXIT THE REPEAT LOOP else if theValue = 0 and theOption = "On" then click theCheckbox # TOGGLE THE STATUS OF THE CHECK BOX, IT'S NOT SET THE WAY WE WANT set statusValidated to true # WE KNOW THE STATUS IS SET THE WAY WE WANT exit repeat # WE'VE DONE WHAT WE WANTED, EXIT THE REPEAT LOOP else set statusValidated to true # WE KNOW THE STATUS IS SET THE WAY WE WANT exit repeat # WE'VE DONE WHAT WE WANTED, EXIT THE REPEAT LOOP end if end try end repeat end tell end tell end tell quit end tell if not statusValidated then # WE COULDN'T VALIDATE THE STATUS OF THE CHECKBOX, LET THE USER KNOW activate display dialog "Unable to set the function key status" giving up after 6 end if end run ########## END APPLESCRIPT CODE ##########
@vegard3055
@vegard3055 2 года назад
@@ClickingKeys wow thanks a lot!! 😊😊
@vegard3055
@vegard3055 2 года назад
@@ClickingKeys I testet it now! since i'm using Norwegian for main language, i needed to change some of the english words in the script, keyboard to "tastatur" (the norwegian word) etc. But den it worked perfect.
@ClickingKeys
@ClickingKeys 2 года назад
@@vegard3055 So happy you were able to make it work! As a note, I have played with Siri running scripts. If you give the app a name that Siri can easily recognize, you could run it by telling Siri to “open application scriptname” or sometimes even just “open scriptname”
Далее
AppleScript Tutorial : Error Handling
6:56
Просмотров 1,7 тыс.
AppleScript Tutorial : Data Types
11:34
Просмотров 3,9 тыс.
AppleScript Tutorial : Schedule with Launchd, not Cron
4:35
AppleScript Tutorial : Alias, HFS & POSIX - OH MY!
4:23
Enums considered harmful
9:23
Просмотров 199 тыс.
AppleScript Tutorial : Dictionaries
4:32
Просмотров 8 тыс.
Самогон из маракуйи
0:59
Просмотров 1,8 млн
Иваново - город невест
0:20
Просмотров 2 млн