Jump to content

Help with Safari apple script workflow


Recommended Posts

Hi. Trying to make an applescript workflow that checks whether tab 1 has url (for example "www.someurlname.com") and enter bunch of text if that's the url. Getting error but can't figure out how to fix it. Thanks.

 

tell application "Safari" to activate
    tell window 1 of application "Safari" to set current tab to tab 1
    tell application "Safari" to return URL of front document
if clipboard starts with "www.someurlname.com" then
    delay 0.01
    tell application "System Events"
        keystroke "{query}"
        key code 36 
    end tell
else
    return
end if
end tell

Link to comment
3 hours ago, iApple said:

Getting error but can't figure out how to fix it.

 

Are we supposed to guess what error you're getting and how to fix it?

 

Please, if you want help with a broken workflow, upload the workflow somewhere and post a link. We can't tell you what the problem is based on a snippet of code and a vague "I'm getting an error".

Link to comment
Posted (edited)

sorry, thought copied & pasted error message.

 

352:360: syntax error: Expected end of line, etc. but found “end tell”. (-2741)

 

Probably I made a simple stupid mistake. Not a coder, searched around forum and came up with code.

 

More specifically, are the 2 lines below correct to find out name of URL? I tried them separately and doesn't seem to work.

 

tell application "Safari" to return URL of front document
if clipboard starts with "www.someurlname.com" then

Edited by iApple
Link to comment
6 minutes ago, iApple said:

Probably I made a simple stupid mistake.

 

It looks like you've made at least two or three.

 

Where is the workflow? I'm not going to spend all day working through your bugs as you fix one and find another, and it is not reasonable for you to expect me to do that.

 

Export the workflow to your Dropbox or iCloud Drive, and post a link.

Link to comment
5 hours ago, iApple said:

Not a coder, searched around forum and came up with code.

 

In that case, you need to give us as much information as possible for us to be able to help you. The Workflow itself, as Dean mentioned, is a good start (it’s possible your Workflow setup is incorrect, not just the code), but you should also explain exactly what you’re trying to achieveXY problems can be needlessly time consuming.


You shouldn’t be pasting the AppleScript code directly in Alfred yet. Use the Script Editor. Once it works there, move to Alfred.


At a glance, your code doesn’t look like it’ll do what you want at all.

 

5 hours ago, iApple said:

tell application "Safari" to return URL of front document
if clipboard starts with "www.someurlname.com" then

 

You’re outputting the URL into nothing, then checking the contents of your clipboard. One of those is not needed. This is likely closer to what you want (untested):

 

tell application "Safari"
	activate
	tell window 1 to set current tab to tab 1
	
	if (URL of front document) starts with "https://www.someurlname.com" then
		delay 0.01
		tell application "System Events"
			keystroke "{query}"
			key code 36
		end tell
	end if
end tell

 

Notice, for example, how you didn’t add the https.

 

Also, whatever you’re trying to type will happen on where your selection is on the page, which might not be where you want.

 

See how there are a ton of things to consider? That’s why we also need to do what your end goal is. The solution to your problem may be significantly simpler and more robust than the path you’re trying to go down.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...