AppleScript : find and set window - safari

I'm try to create a small script to find a safari window based on its URL.
I made this
property checkURL : "https://www.apple.com"
repeat with i in {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
try
tell application "Safari" to set theTab to (first tab of window i whose URL contains checkURL)
tell front window of application "Safari"
set current tab to theTab
end tell
on error
--
end try
end repeat
I'm sur I got it working and one stage but it doesn't seems to work anymore
return :
tell application "Safari"
get tab 1 of window 1 whose URL contains "https://www.apple.com"
--> tab 1 of window id 434
set current tab of window 1 to tab 1 of window id 434
get tab 1 of window 2 whose URL contains "https://www.apple.com"
--> error number -1719 from tab 1 of window 2 whose URL contains "https://acmp.corp.apple.com"
get tab 1 of window 3 whose URL contains "https://www.apple.com"
--> error number -1719 from window 3
get tab 1 of window 4 whose URL contains "https://www.apple.com"
--> error number -1719 from window 4
get tab 1 of window 5 whose URL contains "https://www.apple.com"
--> error number -1719 from window 5
get tab 1 of window 6 whose URL contains "https://www.apple.com"
--> error number -1719 from window 6
get tab 1 of window 7 whose URL contains "https://www.apple.com"
--> error number -1719 from window 7
get tab 1 of window 8 whose URL contains "https://www.apple.com"
--> error number -1719 from window 8
get tab 1 of window 9 whose URL contains "https://www.apple.com"
--> error number -1719 from window 9
get tab 1 of window 10 whose URL contains "https://www.apple.com"
--> error number -1719 from window 10
end tell
PS: I know I should replace the 1/10 list with a list based on the number of window like
tell application "Safari"
set numberOfSafariWindows to length of (get current tab of windows)
end tell
set nlist to {}
repeat with n from 0 to numberOfSafariWindows
set nlist2 to {n + 1}
set nlist to nlist & nlist2
end repeat

Avoid counting when not useful.
set theUrl to "https://www.apple.com"
tell application "Safari"
repeat with thisWindow in every window
repeat with thisTab in (every tab of thisWindow whose URL contains theUrl)
set current tab of thisWindow to thisTab
end repeat
end repeat
end tell

I changed the code and it's seems to work
tell application "Safari"
--Variables
set windowCount to number of windows
set docText to ""
--Repeat for Every Window
repeat with x from 1 to windowCount
set tabcount to number of tabs in window x
--Repeat for Every Tab in Current Window
repeat with y from 1 to tabcount
--Get Tab Name & URL
set tabName to name of tab y of window x
set tabURL to URL of tab y of window x
if tabURL contains "https://www.apple.com" then
tell application "Safari"
tell window x
set current tab to tab y
end tell
end tell
end if
end repeat
end repeat
end tell

Related

How to detect if the previous heading in the document is heading 1 or heading 7 through VBA

My templates contain Heading 1 to 5 for normal text and Appendix headings (based on heading 7, 8 and 9).
Chapter text
Appendix A Chapter text
The table and figure captions are different: based on Heading 1 or Appendix.
Table 1.1 or
Table A.1
Works fine. But ... for now I have two buttons in the ribbon to insert the table caption:
Insert table caption
Insert table caption appendix
Same for figure caption.
There must be a way to detect the previous main heading (heading 1 or heading 7 or outlinelevel 1 or 7), so I only need one button to insert a table (or figure) caption. But I just can't find it.
Does anyone have a clue? Thank you.
Helma
There is no specific property in Word that will return the previous level with outline level x. You will need to create a macro that loops backwards from the current paragraph until it finds outline level 1 or outline level 7.
Here are two examples of a function that return true if a preceding heading level was outline level 7 and false if it was outline level 1. The code compile without error and have no findings when inspected with the RubberDuck code inspector.
Option Explicit
'Recursive function
Public Function IsAppendixR(ByVal ipPara As Range) As Boolean
Select Case ipPara.Paragraphs.Item(1).OutlineLevel
Case 1
IsAppendixR = False
Case 7
IsAppendixR = True
Case Else
IsAppendixR = IsAppendixR(ipPara.Previous)
End Select
End Function
' Loop version
Public Function IsAppendixL(ByVal ipPara As Range) As Boolean
Do
Select Case ipPara.Paragraphs.Item(1).OutlineLevel
Case 1
IsAppendixL = False
Exit Function
Case 7
IsAppendixL = True
Exit Function
Case Else
ipPara.Previous
End Select
Loop
End Function
Word contains a hidden bookmark that you can use to get the range of the current heading level. By testing the outline level of the first paragraph in that range you can determine whether you are in an appendix.
Sub TestIsAppendix()
If IsAppendix(Selection.Range) Then MsgBox "In appendix"
End Sub
Public Function IsAppendix(ByVal para As Range) As Boolean
Dim headingBlock As Range
Set headingBlock = para.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
Select Case headingBlock.Paragraphs.Item(1).OutlineLevel
Case 7 To 9
IsAppendix = True
Case Else
IsAppendix = False
End Select
End Function

Calabash-Android loop through ListView

I've written a feature:
Feature: Open List item
Scenario: As a valid user I can open list item
When I press list item number 0
Then I do something...
Then I go back
What I would need is to open every item of ListView (not only 0th), so how could I specify a loop that would in the end iterate through whole ListView, or some specified maximum index - ie. for parameter value 5 it should execute this scenario for 0th, 1th, 2nd, 3rd, 4th and 5th item.
So, two questions:
1) How to create a loop?
2) How to parametrize execution
Regards,
Milos
1. If you know the exact loop count, you can use scenario outline in cucumber.
Feature: Open List item
Scenario: As a valid user I can open list item
When I press list item number <count>
Then I do something...
Then I go back
Examples:
| count |
| 1 |
| 2. |
| .. |
| n |
More details about scenario outline: https://github.com/cucumber/cucumber/wiki/Scenario-Outlines
Or
2. You can get count using query() & iterate using for each loop in ruby
For getting count query("view").count
Get the count.
Store it in variable
Loop it in step definition

Moving between cells based on checkbox status

I am trying to generate a unique output when a button is clicked on one sheet that will depend on the state of a group of check boxes.
There is a group of ten boxes, any of which can be selected for a maximum of ten. When the button is clicked, the name of each check box will appear sequentially. So for example:
Check box 1 and 3 are checked, the button is clicked, then the output to the cells will look like: [Check Box1] [Check Box3]
However if boxes 1 2 3 9 are checked, it will display:
[Check Box1] [Check Box2] [Check Box3] etc....
My main issue is that I only want the name of the checkbox to appear as a heading if it is selected.
Assuming "forms" checkboxes (vs. ActiveX type)
dim i, n, s
n = 0
for i = 1 to 10
s = "Check Box " & i
if activesheet.checkboxes(s).Value = 1 then
Activesheet.range("A1").offset(0, n).value = s
n = n + 1
end if
next i

Sum data in a column based on another column Report Builder - Sharepoint

I have a project where I have to report stop times of different production lines.
I have to make a report file with Report Builder and my problem for the moment is that I have to sum all the stop times that where entered for the same line.
The stop times are entered on SharePoint (using a form from InfoPath) and stored in a SharePoint List.
My data list is presented like this:
LINES ---- TIME(min)
Line 1 ---- 4
Line 2 ---- 2
Line 1 ---- 3
Line 3 ---- 8
Line 4 ---- 9
Line 2 ---- 2
Line 3 ---- 4
Line 5 ---- 5
Line 5 ---- 8
I want to sum all the stop time for each line (In my report generated with Report Builder). So I'll have "Line1 -> 7", "Line 2 -> 4",...
Do you have any idea how I could do it?
Ask if you need more informations...
Thank you for your help!
This should be fairly easy; set up a table drawing the data in exactly that format, then right click the "Details" row in "Row Groups" at the bottom of Report Builder and click "Group Properties". Press Add, and select your "Lines" field, then press OK. Finally, change the expression populating the "Time" column in your table to =SUM(Fields!.Value).
What this will do is collapse the table to show one line per distinct value it finds in the "Lines" column, then tells it to simply add all the values it collapses together. The effect will be that it sums up the Time column for each distinct value it finds in the Lines column.

Determine section for selected row from NSOutlineView

OK so I've got a sidebar built using an NSOutlineView. I currently have two sections in the sidebar which can be expanded/contracted. I would like to be able to determine which section the selected row belongs to.
- Section 1
-- Item 1
-- Item 2
-- Item 3
- Section 2
-- Item 4
-- Item 5
The problem is that the selectedRow value changes depending on whether sections are expanded or not. Is there no easy way to determine which section the row belongs to without manually keeping track of expansion/contraction and the number of items in each section?
Try this:
//returns id of section, where currentRow is a selectedRow
id section = [yourNSOutlineView parentForItem:[yourNSOutlineView itemAtRow:selectedRow]];
You could call [NSOutlineView itemAtRow:] with the index of the selected row.