Can you trigger shortcut or BetterTouchTool when new app is installed?

Hi, I want to trigger automation if the new app is installed, or to put it another way, if a new file is added to the Application folder. Then, I want to display some text with a button.

Is it possible to do it with Shortcuts/Automator or with BetterTouchTool? I cannot find a trigger that fulfills these requirements.

How about using folder actions or Hazel to monitor your Applications folder and trigger an automation?

1 Like

How do you configure a folder action? I haven’t heard about that yet. I have been experimenting with the 14-day trial of Hazel, but I haven’t purchased it yet, so I am looking for a workaround without using Hazel.

Okay, thank you. I googled it and figure it out. I edit some predefined script and now it kinda works. One issue is, that script is run twice. First time when an application is installing and the second time after finished installing. But I guess this is how it works and it recognizes new items twice.

Besides this one problem, it is what I wanted. Thank you again.

I’m sure you could modify the folder action script to deal with that by adding a memory to it (a bit of persistent storage about the last thing added - if not the same, update, if the same carry out the desired action).

As for the double trigger, I don’t know the case for sure, as I have never had a need to automate action on Application folders.

Out of interest, and to help anyone in the future who comes across the thread can you share a link to the base script you ended up using, and what the context of your use is - i.e. what are you automating after an installation (e.g. Adding app name to a running list of installed apps and installation dates).

As I am building a database of all my applications in Notion so I want a reminder to add new entry after installing new application and open Notion page with this database. This is the script I am using:

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	try
		tell application "Finder"
			--get the name of the folder
			set the folder_name to the name of this_folder
		end tell
		
		-- find out how many new items have been placed in the folder
		set the item_count to the number of items in the added_items
		--create the alert string
		set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
		if the item_count is greater than 1 then
			set alert_message to alert_message & (the item_count as text) & " new items have"
		else
			set alert_message to alert_message & "One new item has "
		end if
		set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
		set the alert_message to (the alert_message & return & return & "Would you like to display application in folder and open Notion page?")
		
		display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
		set the user_choice to the button returned of the result
		
		if user_choice is "Yes" then
			tell application "Finder"
				--go to the desktop 
				activate
				--open the folder
				open this_folder
				--select the items
				reveal the added_items
			end tell
			tell application "Notion"
				open location "notion://www.notion.so/xxxxxx"
			end tell
		end if
	end try
end adding folder items to

I modified default Script called “add - new item alert” which is in the “Folder Action Scripts” folder.

This is path to this folder: “/Library/Scripts/Folder Action Scripts”

I have not modified it yet, so it is still with a double trigger. Maybe you can help me with that if it is something easy. :wink:

1 Like

Okay, so like I said, you want to add some history to it. AppleScript doesn’t have data persistence between script runs, so when you want to store say the name of the application added in a file. Then, as above, on subsequent triggers if the name is different, overwrite it into the file. If it is the same, trigger your alert.

One things that may be an issue is app updates. They might also trigger your alert, so you may actually need another list to check too of all installed apps and then check in that to see if it is an update or not.

For a future enhancement, AppleScript could be used to call say curl on the command line, and you could use that to update Notion directly. You could capture any additional manual input in the AppleScript before updating if necessary, but I suspect you can automate a good chunk there… if you feel it is worth the effort.

Another alternative may be a scheduled check of an app list. Each day for example an app listing could be generated and compared to the previous day’s. Any differences are then flagged up to you or automatically included. It depends if you like to action the additions asap after installling, or batch them up.

Hope that helps.

2 Likes

Thank you @sylumer it definitely helped. I look more into it and maybe try to integrate more with Notion API. It can be quite a challenge. :smiley: