Jump to content

Search the Community

Showing results for tags 'JXA'.



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 8 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 certainly understand — applescript is a pain, and since each browser implements this functions however they want, finding the best way to do it with each one can be difficult, so here’s the code for some of them. The code for this might seem massive, but is actually short. 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. -- Google Chrome 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 -- Google Chrome Canary tell application "Google Chrome Canary" to return title of active tab of front window tell application "Google Chrome Canary" to return URL of active tab of front window -- Chromium tell application "Chromium" to return title of active tab of front window tell application "Chromium" to return URL of active tab of front window -- Opera tell application "Opera" to return title of active tab of front window tell application "Opera" to return URL of active tab of front window -- Vivaldi tell application "Vivaldi" to return title of active tab of front window tell application "Vivaldi" to return URL of active tab of front window -- Brave tell application "Brave" to return title of active tab of front window tell application "Brave" to return URL of active tab of front window -- Safari tell application "Safari" to return name of front document tell application "Safari" to return URL of front document -- Safari Technology Preview tell application "Safari Technology Preview" to return name of front document tell application "Safari Technology Preview" to return URL of front document -- Webkit tell application "Webkit" to return name of front document tell application "Webkit" to return URL of front document -- This example will return both the title and URL for the frontmost tab of the active browser, separated by a newline. -- 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 = "Google Chrome") or (frontApp = "Google Chrome Canary") or (frontApp = "Chromium") or (frontApp = "Opera") or (frontApp = "Vivaldi") or (frontApp = "Brave") 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 = "Safari") or (frontApp = "Safari Technology Preview") or (frontApp = "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. // Google Chrome Application('Google Chrome').windows[0].activeTab.name() Application('Google Chrome').windows[0].activeTab.url() // Google Chrome Canary Application('Google Chrome Canary').windows[0].activeTab.name() Application('Google Chrome Canary').windows[0].activeTab.url() // Chromium Application('Chromium').windows[0].activeTab.name() Application('Chromium').windows[0].activeTab.url() // Opera Application('Opera').windows[0].activeTab.name() Application('Opera').windows[0].activeTab.url() // Vivaldi Application('Vivaldi').windows[0].activeTab.name() Application('Vivaldi').windows[0].activeTab.url() // Brave Application('Brave').windows[0].activeTab.name() Application('Brave').windows[0].activeTab.url() // Safari Application('Safari').documents[0].name() Application('Safari').documents[0].url() // Safari Technology Preview Application('Safari Technology Preview').documents[0].name() Application('Safari Technology Preview').documents[0].url() // Webkit Application('Webkit').documents[0].name() Application('Webkit').documents[0].url() // This example will return both the title and URL for the frontmost tab of the active browser, separated by a newline. // 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) if (['Google Chrome','Google Chrome Canary','Chromium','Opera','Vivaldi','Brave'].indexOf(frontmost_app_name) > -1) { var current_tab_title = frontmost_app.windows[0].activeTab.name() var current_tab_url = frontmost_app.windows[0].activeTab.url() } else if (['Safari','Safari Technology Preview','Webkit'].indexOf(frontmost_app_name) > -1) { 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') } console.log(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. Hi all! First post here. A workflow of mine involves having a script launch a bookmarklet in Google Chrome. I can, it is true, put the JS code to be executed directly into my script, but that means changing my code in 2 places every time I change something. So with Applescript, opening a bookmark in Chrome is trivial: tell application "Google Chrome" if not (exists window 1) then reopen set coef to URL of bookmark item "Coef" of bookmark folder "Bookmarks Bar" open location coef end tell But when trying this in JXA, everything goes to hell. I've tried countless variations on the following code, var app = Application('com.google.Chrome') var frontWindow = app.windows[0] var myBM = app.bookmarkFolders.whose({title: "Bookmarks Bar"}) var myBM = app.bookmarkFolders["Bookmarks Bar"] var myBM = app.bookmarkFolders.title("Bookmarks Bar") //etc ad nauseam and cannot for the life of me get a handle on a bookmark folder, let alone a bookmark item. bookmarkFolder vs. bookmarkFolders, nothing helped. The last line actually got me an array with the names of the two top-level folders, but that's the closest I got to anything. Anybody has an idea how this gets done? Thanks!
  3. This is a simple workflow for quick full text search inside current pathfinder folder. It can: filter files in your current pathfinder folder full text search in your folder THERE IS NO FINDER SUPPORT - I don't use it and Im too lazy to add it - if you want you can add it yourself github download dependency - http://geoff.greer.fm/ag/speed/ Search Options: -a --all-types Search all files (doesn't include hidden files or patterns from ignore files) -D --debug Ridiculous debugging (probably not useful) --depth NUM Search up to NUM directories deep (Default: 25) -f --follow Follow symlinks -F --fixed-strings Alias for --literal for compatibility with grep -G --file-search-regex PATTERN Limit search to filenames matching PATTERN --hidden Search hidden files (obeys .*ignore files) -i --ignore-case Match case insensitively --ignore PATTERN Ignore files/directories matching PATTERN (literal file/directory names also allowed) --ignore-dir NAME Alias for --ignore for compatibility with ack. -m --max-count NUM Skip the rest of a file after NUM matches (Default: 10,000) --one-device Don't follow links to other devices. -p --path-to-agignore STRING Use .agignore file at STRING -Q --literal Don't parse PATTERN as a regular expression -s --case-sensitive Match case sensitively -S --smart-case Match case insensitively unless PATTERN contains uppercase characters (Enabled by default) --search-binary Search binary files for matches -t --all-text Search all text files (doesn't include hidden files) -u --unrestricted Search all files (ignore .agignore, .gitignore, etc.; searches binary and hidden files as well) -U --skip-vcs-ignores Ignore VCS ignore files (.gitignore, .hgignore, .svnignore; still obey .agignore) -v --invert-match -w --word-regexp Only match whole words -z --search-zip Search contents of compressed (e.g., gzip) files File Types: The search can be restricted to certain types of files. Example: ag --html needle - Searches for 'needle' in files with suffix .htm, .html, .shtml or .xhtml.
  4. I have an Alfred workflow based on a JXA script. It acts as a control mechanism for focusatwill.com (an online music streaming service). It has basic functionality, play/pause, skip track... This was working fine in an earlier version, interacting with the page using query selectors, e.g. tab.execute({ javascript: "document.querySelector('.playerControls .playButton').click();" }) This site recently refactored their UI to use React. My basic controls still work (using querySelector), but one part of the setup (changing the genre) has broken. It used to use querySelectorAll for this task, but in the new React UI, the controls I need to reach don't exist unless you click in the UI ... In any case, the developers exposed an API in the site code, so I can do stuff like window.faw.play() window.faw.skip() window.faw.genre(genreId) And doing that in the developer console in Chrome works fine. But if I try to do the same using tab.execute in JXA (from Alfred), nothing happens. I'm guessing that I'm running afoul of the security model in Chrome. Does anyone know if what I'm trying to do is even possible (from Alfred/JXA)? Or am I going to have to try to do this as a Chrome extension instead? If it's helpful, here is the repository: https://github.com/tangledhelix/focusatwill-in-google-chrome And there's some discussion between me and someone at focusatwill.com on this commit: https://github.com/tangledhelix/focusatwill-in-google-chrome/commit/eb339cba143cdbc2593c73869e11bcd70f18042a
  5. A workflow for quick adding new tasks into selected OmniFocus project. Preview: It can: Filter tasks inside project Add new tasks with notes and clipboard content Run terminal command after your task is finished (mostly for git or whatever) Open note links (all at once) (discontinued in version 2) Copy note Delete tasks Quickly open tasks in omnifocus (discontinued in version 2) Complete tasks - version 2 - Work with completed tasks Search tasks and projects (both completed and uncompleted) in of database Change project selection Complete projects Flag unflag tasks and projects Added basic fantastical 2 support (disabled by default) Workflow now reopens itself with appleScript - Application('Alfred 3').runTrigger('sidekick',{inWorkflow:'com.sidekick.modi',withArgument:mode}); github download Version 2 works using omnifocus cached database - It is much faster than using applescript. I work with appstore omnifocus - so there is appstore cache folder set by default in the settings - https://www.dropbox.com/s/q1lbjwozpn84sh3/2016-10-09 18.09.46.gif?dl=0 - If you use non appstore version you should change db variable in the settings to ~/Library/Containers/com.omnigroup.OmniFocus2/Data/Library/Caches/com.omnigroup.OmniFocus2/OmniFocusDatabase2 to run terminal commands you need to add your script into the project description surrounded with | - for example |open http://www.alfredforum.com/|- will open alfred forum after every task you finish. use $1 to access task title and $2 to get task note This workflow is not 100% ready yet - there are a lot of things I'm planing to add: add new tasks (when started and finished) into calendar with link to the omnifocus task Timing app support (get start finish date and generate report what exactly I was doing during the task) finder/pathfinder support (add selected files with @2) chrome/safari support (add tabs urls with @3) automatically change settings when user opens workflow first time (in case user has not appstore version or does not have any third party apps) edit tasks inside alfred (do not know if it is usefull) change task parents creating new projects inside sidekick If you have any ideas how I can make this workflow better I will be glad to implement them
  6. Hello, I use a simple jxa for getting url from devonthink this is the code Im using function run(argv) { var q=argv[0].split('/'),q=q[q.length-1].split('.')[0]; var qq=Application('/Applications/DEVONthink Pro.app').getRecordWithUuid(q).url(); return qq } But it adds %0A in the end of every link - this is not a script bug - this is an alfred 3 bug osx 10.11.5, alfred v 3.0 [652]
  7. I've been playing around with the new JavaScript for Automation in Yosemite, and I must say that I've been smitten. It so much more predictable than AppleScript. However, I'm a noob when it comes to scripting in general. So, on that note, does anyone know how I should be implementing JavaScript into my Alfred workflows? It won't run in a NSAppleScript action, nor will it run if I put in in a Run Script action with the language set to osascript. I was able to get it to work if I placed the script inside the workflow folder and ran it with a bash command, but then how do I grab the arguments in the script? Thanks!
×
×
  • Create New...