AppleScript Error While Programming - applescript

I am still new to programing but I have a AppleScript Error that I need help with.
I am creating a prank using AppleScript but this error message showed up when I tried to compress the file.
Expected “else”, etc. but found end of script.
Here is my code. Please help me fix this! Thanks!
display dialog "Virus Detected" buttons {"Shut Down", "Crash CPU"} default button 2
if the button returned of the result is "Shut Down" then
beep 10
display dialog "Virus Downloaded. Commencing Virus Deletion Process. Shutting Down"
say "Virus Deletion Process FAILED. Virus Downloaded. Shut Down Has Been Overrided"
display dialog "All Systems Has Been Hacked. Computer Is Now Overloading"
display dialog "Passwords Have Been Hacked" buttons {"Abort"}
if the button returned of the result is "Abort" then
display dialog "About Has Been Overrided. Passwords Are Now Uploading" buttons {"Cancel"}
if the button returned of the result is "Cancel" then
display dialog "Overrided. Uploading Complete. Deleting ALL Files From Main Data Base."
say "Deletion Complete"
display dialog "Shutting Down"
tell application "Finder" to shut down
else
beep 10
display dialog "Virus Downloaded Successfully. Computer Has Been Hacked"
say "Virus Has Hacked Into The Motherboard"
display dialog "Deleting All Files. Restoring From Backup"
say "No Backups Were Found"
display dialog "Deleting ALL Data. Computer Is Now Crashing. Shutting Down"
tell application "Finder" to shut down
end if

In line 8 and 10 there are two if clauses.
Each of them must be balanced with an end if (before the else)

Related

Applescript intermittently fails when moving selected email messages to folder

hope someone can tell me what I am doing wrong. I am an applescript newby, with help from other posts was able to use automator, applescript & keyboard shortcut to move selected messages to an outlook folder. Worked great. I transferred to another mac, works fine there. Then intermittently I get an error message on both macs:
The action "Run Applescript" encountered an error: "No messages selected. Select at least one message."1
I initially thought it was related to when I last opened up Outlook as it seemed to fix itself after a few minutes. Then problem comes back, no rhyme or reason I can perceive. Yes, I do in fact select a message first.
I made two copies of script, differences are folder names. Two different hotkeys attached, option+B for one folder option+P for another. Same error if I use hotkey or go to outlook/services then select the script
Any clue what I am doing wrong? thanks in advance for any insight!
Outlook for mac / O365 v: 16.62 (22061100)
osx big sur v: 11.6 (20G165)
here is script:
on run {input, parameters}
tell application "Microsoft Outlook"
activate
set msgSet to current messages
if msgSet = {} then
error "No messages selected. Select at least one message."
error -128
end if
set theMsg to item 1 of msgSet
set theAccount to account of theMsg
set archiveFolder to folder "Broker Correspondence" of theAccount
repeat with aMessage in msgSet
move aMessage to archiveFolder
end repeat
end tell
return input
end run

AppleScript: Error -15267 Copying to External

I recently started AppleScript and wanted to slowly getting into scripting and hoping someone can help me with a block I have ran into. Tried a few things and moving pieces around and changing identifiers but don't know what I should be looking for to change. Hoping someone can help me out and explain my flaws.
Background Story: Trying to test a script to back up of a user account home folder to an external drive.
What I have first: drive verification to make sure there is a drive plugged into the computer. Followed by setting source and destination. Then tried compiling an if then statement to single out 2 folders I don't want to be copied over (only focusing on the user folder, but unsure if that is correct and will need that looked at too). I get my error at the duplicate command: "Finder got an error: An item with the same name already exist in this location." However, there is nothing the external so I have no clue what else to do. Any advice would be helpful.
This is the code I have to start with:
tell application "System Events" to set diskNames to name of every disk
if "Untitled" is in the diskNames then
display dialog "Disk is mounted" buttons {"OK"} default button 1 with icon 1
else
display dialog "No disk found" buttons {"OK"} default button 1 with icon 1
end if
tell application "Finder"
set source_folder to "Macintosh HD:Users:"
set tar_disk to "Untitled:"
if source_folder is not {"administrator", "Shared"} then
with timeout of 3600 seconds -- 2 hours
duplicate source_folder to tar_disk
end timeout
else
display dialog "No folder detected" buttons {"OK"} default button 1 with icon 1
end if
end tell
You are able to copy only your own home folder with the Finder, you don't have permissions to copy the home folders of other users (except Shared).
Basically it's good habit to add Finder specifiers to literal strings representing files, folders and disks for example
set tar_disk to disk "Untitled"
Since there is a home property pointing to the current home folder you can write
tell application "Finder"
set tar_disk to disk "Untitled"
with timeout of 3600 seconds -- 2 hours
duplicate home to tar_disk
end timeout
end tell
There is an important caveat: The Finder copies only the visible files and folders. If AppleShowAllFiles is set to false all files starting with a dot are ignored. To copy the entire home folder something like the shell rsync command is the better choice – also for speed reasons.

Applescript application and Open with

I have a simple script
on run
display dialog "Hello" buttons {"Ok"}
end run
I saved it as application (let's say myapp.app)
If I just launch it from finder by double clicking then it works (i.e. shows the dialog box), but I want to use it for opening files.
The problem:
For example I have file.xyz, then right-click it to "open with" and choose my.app. In this case my.app doesn't start (no icon at the dock panel, no dialog box shown).
You can use an open handler to drag items on the application like this:
on open of theFiles
-- Executed when files are dropped on the application
display dialog "There are " & (count of theFiles) & " files dropped" buttons {"OK"}
end open

Applescript can't open app

I've written a Mac app that isn't scriptable (yet), and I'd like to run it with Applescript. Either of the following scripts get "An error of type-10660 has occurred.". After hours of searching, I haven't found a solution, or an explanation of the error.
if exists application "RotorDCU" then
display dialog "Found." buttons {"OK"}
else
display dialog "Not found." buttons {"OK"}
end if
tell application "RotorDCU"
activate
end tell
Error -10660 is a Launch Services error, explained in the interface file LSInfo.h:
The app cannot be run when inside a Trash folder
Is RotorDCU in the Trash, perchance?

AppleScript - Help with Safari

I've been appointed the task of creating an applicaton that must
Display a dialog saying "The webpage has finished loading." when a webpage finishes loading
Determine how many items are currently in the process of downloading
For number 1, I've tried doing if the URL of the front document is "http://applescript.weebly.com" then, but the then part always runs even if the webpage doesn't load!
For number 2, I've tried this...
tell application "Safari" to get every item of window "Downloads"
But this returns references to every item, even the ones that havae already been downloaded!
Conclusion: I need help. :S
Display a dialog saying "The webpage has finished loading." when a webpage finishes loading.
There is no way to do this with just pure AppleScript. However, you can use a combination of AppleScript and javascript...
tell application "Safari"
repeat until (do JavaScript "document.readyState" in document 1) is "complete"
end repeat
display dialog "The webpage has finished loading."
end tell
WARNING: If the webpage doesn't load for some reason, the script will be stuck forever in an infinite repeat loop.
Determine how many items are currently in the process of downloading.
When you download files, they are temporarily given the name extension download, so AppleScript can tell the Finder to get the files with that extension and create an alert/dialog:
set the download_count to 0
set the download_folder to (path to downloads folder) as alias --or wherever the items are being downloaded
tell application "Finder" to set the download_count to the count of (every item of the download_folder whose name extension is "download")
if the download_count is 0 then
display dialog "There are currently no downloads in progress."
else if the download_count is 1 then
display dialog "There is currently one download in progress."
else
display dialog "There are currently " & the download_count & " downloads in progress."
end if
P.S. Thanks for honoring my web site!
I wrote the script below in AppleScript Editor to open my browser, display my ISP in the URL, go through the login process and connect to the internet. Is working perfectly. I want to add or modify it to ping "www.google.com" every hour or so, and if my connection has dropped to repeat the process below again, which will connect my computer back to the internet.
I'm just learning this script writing thing and don't have a very good undersatnding of how it works yet, so if anyone can help please expalin it in simple terms for me. Very much appreciated.
tell application "Safari"
activate
tell application "System Events"
open location "https://basrah.uswicom.com/login.php"
delay 1
keystroke return
delay 3
keystroke tab
keystroke (ASCII character 29)
delay 1
delay 1
keystroke tab
delay 1
keystroke "123456789"
delay 1
keystroke return
delay 1
keystroke return
end tell
end tell

Resources