Jump to content

Hidden trigger


RuslanI

Recommended Posts

I've created a macro in Keyboard Maestro to create nested folders in Finder with the following code

(Just in case there is something in the code, although i could not see anything)

try
	tell application "Finder"
		set selectedItem to selection
		set currentPath to ((the first item of the selectedItem) as alias)
		set parentPath to ""
		
		if (currentPath as string) ends with ":" then
			-- it is a folder
			set the parentPath to currentPath
		else
			-- it is a file
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
			set the parentPath to (text items 1 thru -2 of (currentPath as string)) as string
			set AppleScript's text item delimiters to od
		end if
		
		set newFolder to (my createFolder(parentPath))
		
	end tell
on error -- no folder or file is selected
	tell application "Finder"
		set the currentPath to (folder of the front window as alias)
		set parentFolder to currentPath
		
		set newFolder to (my createFolder(currentPath))
		
	end tell
end try


on createFolder(folderLocation)
	tell application "Finder"
		set thisFolder to make new folder at folderLocation
		
		set selection to thisFolder
		tell application "System Events"
			keystroke return
			quit -- if i don't do this system events seems to hang???
		end tell
		return thisFolder
	end tell
end createFolder

I set it to trigger on CTRL+CMD+F. 

Now when i trigger this shortcut, a folder gets created as expected but then a focus gets stolen and Alfred iTunes mini player pops out. I searched through every setting in Alfred and i could not find where i have CTRL+CMD+F assigned. But if i disable Alfred then everything works as expected. 

Is there any way i can troubleshoot this issue?

Link to comment

I've created a macro in Keyboard Maestro to create nested folders in Finder with the following code

(Just in case there is something in the code, although i could not see anything)

try
	tell application "Finder"
		set selectedItem to selection
		set currentPath to ((the first item of the selectedItem) as alias)
		set parentPath to ""
		
		if (currentPath as string) ends with ":" then
			-- it is a folder
			set the parentPath to currentPath
		else
			-- it is a file
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
			set the parentPath to (text items 1 thru -2 of (currentPath as string)) as string
			set AppleScript's text item delimiters to od
		end if
		
		set newFolder to (my createFolder(parentPath))
		
	end tell
on error -- no folder or file is selected
	tell application "Finder"
		set the currentPath to (folder of the front window as alias)
		set parentFolder to currentPath
		
		set newFolder to (my createFolder(currentPath))
		
	end tell
end try


on createFolder(folderLocation)
	tell application "Finder"
		set thisFolder to make new folder at folderLocation
		
		set selection to thisFolder
		tell application "System Events"
			keystroke return
			quit -- if i don't do this system events seems to hang???
		end tell
		return thisFolder
	end tell
end createFolder

I set it to trigger on CTRL+CMD+F. 

Now when i trigger this shortcut, a folder gets created as expected but then a focus gets stolen and Alfred iTunes mini player pops out. I searched through every setting in Alfred and i could not find where i have CTRL+CMD+F assigned. But if i disable Alfred then everything works as expected. 

Is there any way i can troubleshoot this issue?

 

Have you looked in Alfred's Preferences under the Features tab? In the list on the left hand side, select iTunes. All settings (including hotkeys) pertaining to Alfred's Mini Player, would be located there.

Link to comment

OK, i've got it figured out. I used Karabiner event viewer and indeed it showed that when i pressed CTRL+CMD+F , somehow a return key was triggered. So i scanned the script code more closely and indeed it does simulate return key press. And iTunes mini player was setup to CTRL+CMD+Return. So once i triggered the script while it ran it triggered a return key and it registered while i was still holding CTRL+CMD so hence it activated Alfred's iTunes mini player. 

So if anybody is having problems with shortcuts behaving strangely, Karabiner's Event Viewer might be a good place to start the investigation.

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...