Jump to content

Search the Community

Showing results for tags 'how to'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Alfred 3
  • Make the Most of Alfred
    • Discussion & Help
    • Bug Reports
    • Alfred Feature Suggestions
    • Themes
  • Alfred Workflows
    • Share your Workflows
    • Workflow Help & Questions
  • Alfred v2 Themes
  • Alfred Remote for iOS
    • Alfred Remote Discussion & Help
    • Remote Connection Troubleshooting

Categories

  • Articles
    • Forum Integration
    • Frontpage
  • Pages
  • Miscellaneous
    • Databases
    • Templates
    • Media

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Twitter


Website URL


Jabber


Location


Interests

Found 3 results

  1. I’ve been seeing a lot of workflows that need to interact with a browser via AppleScript (usually to get a page’s url), but most of them seem to settle on a single browser (usually Safari), which is a shame. I can understand — applescript is a pain, and since each browser implements these functions however they want, finding the best way to do it with each one can be difficult, so here’s the code for most of them. The code for this may seem massive, but it is not. Read the comments to understand when to use what. You can find the latest version of this as a gist. -- AppleScript -- -- This example is meant as a simple starting point to show how to get the information in the simplest available way. -- Keep in mind that when asking for a `return` after another, only the first one will be output. -- This method is as good as its JXA counterpart. -- Chromium variants include "Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge". -- Specific editions are valid, including "Google Chrome Canary", "Microsoft Edge Dev". -- "Google Chrome" Example: tell application "Google Chrome" to return title of active tab of front window tell application "Google Chrome" to return URL of active tab of front window -- "Chromium" Example: tell application "Chromium" to return title of active tab of front window tell application "Chromium" to return URL of active tab of front window -- Webkit variants include "Safari", "Webkit". -- Specific editions are valid, including "Safari Technology Preview". -- "Safari" Example: tell application "Safari" to return name of front document tell application "Safari" to return URL of front document -- "Webkit" Example: tell application "Webkit" to return name of front document tell application "Webkit" to return URL of front document -- This example returns both the title and URL for the frontmost tab of the active browser, separated by a newline. -- For shorter code inclusive of all editions, only the start of the application name is checked. -- Keep in mind that to be able to use a variable in `tell application` — via `using terms from` — we’re basically requiring that referenced browser to be available on the system. -- That means that to use this on "Google Chrome Canary" or "Chromium", "Google Chrome" needs to be installed. Same for other browsers. -- This method also does not exit with a non-zero exit status when the frontmost application is not a supported browser. -- For the aforementioned reasons, this method is inferior to its JXA counterpart. tell application "System Events" to set frontApp to name of first process whose frontmost is true if (frontapp starts with "Google Chrome") or (frontApp starts with "Chromium") or (frontApp starts with "Opera") or (frontApp starts with "Vivaldi") or (frontApp starts with "Brave Browser") or (frontApp starts with "Microsoft Edge") then using terms from application "Google Chrome" tell application frontApp to set currentTabTitle to title of active tab of front window tell application frontApp to set currentTabUrl to URL of active tab of front window end using terms from else if (frontApp starts with "Safari") or (frontApp starts with "Webkit") then using terms from application "Safari" tell application frontApp to set currentTabTitle to name of front document tell application frontApp to set currentTabUrl to URL of front document end using terms from else return "You need a supported browser as your frontmost app" end if return currentTabUrl & "\n" & currentTabTitle // JavaScript for Automation (JXA) // // This example is meant as a simple starting point to show how to get the information in the simplest available way. // Keep in mind that when asking for a value after another, only the last one one will be output. // This method is as good as its AppleScript counterpart. // Chromium variants include "Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge". // Specific editions are valid, including "Google Chrome Canary", "Microsoft Edge Dev". // "Google Chrome" Example: Application('Google Chrome').windows[0].activeTab.name() Application('Google Chrome').windows[0].activeTab.url() // "Chromium" Example: Application('Chromium').windows[0].activeTab.name() Application('Chromium').windows[0].activeTab.url() // Webkit variants include "Safari", "Webkit". // Specific editions are valid, including "Safari Technology Preview". // "Safari" Example: Application('Safari').documents[0].name() Application('Safari').documents[0].url() // "Webkit" Example: Application('Webkit').documents[0].name() Application('Webkit').documents[0].url() // This example returns both the title and URL for the frontmost tab of the active browser, separated by a newline. // For shorter code inclusive of all editions, only the start of the application name is checked. // This method is superior to its AppleScript counterpart. It does not need a "main" browser available on the system to reuse the command on similar ones and throws a proper error code on failure. const frontmost_app_name = Application('System Events').applicationProcesses.where({ frontmost: true }).name()[0] const frontmost_app = Application(frontmost_app_name) const chromium_variants = ['Google Chrome', 'Chromium', 'Opera', 'Vivaldi', 'Brave Browser', 'Microsoft Edge'] const webkit_variants = ['Safari', 'Webkit'] if (chromium_variants.some(app_name => frontmost_app_name.startsWith(app_name))) { var current_tab_title = frontmost_app.windows[0].activeTab.name() var current_tab_url = frontmost_app.windows[0].activeTab.url() } else if (webkit_variants.some(app_name => frontmost_app_name.startsWith(app_name))) { var current_tab_title = frontmost_app.documents[0].name() var current_tab_url = frontmost_app.documents[0].url() } else { throw new Error('You need a supported browser as your frontmost app') } current_tab_url + '\n' + current_tab_title Other browsers Firefox Absent since although it’s possible to get the window’s title, it’s not possible to get its URL (it used to be, before version 3.6). It’s possible via hacky ways that consist of sending keystrokes, but those can be unreliable. This bug is being tracked in Bugzilla.
  2. I am trying to use a custom binary in a Script Filter. So far, there is only one issue: When I activate the script filter, the binary is called. If I close Alfred before the binary process terminates, that process begins to steal all of my RAM, as if in an infinite loop. Normally, it runs around 500KB of RAM for a split second; when improperly terminated, it will take up to 2GB until I quit the process with Activity Monitor. My script filter contains this code: ./binary "#{query}" How can I prevent the process from going haywire every time Alfred closes before the execution completes? (I do have access to the source code, if needed.)
  3. just walking into this = there's a lot of directions. is there a doc or something i can follow to get started using Alfred 2.0? Tia,
×
×
  • Create New...